Forum > LCL
BufDataset and LoadFromStream problem
iru:
Gentlefolk,
Lazarus 0.9.29 snapshot (using to address other issues with dbgrid), windows xp, SP-3.
I have a peice of delphi code which I have migrated to lazarus. The Lazarus code is to load the 'fields' in a .CSV file to a BufDataset, the code crashes on 'LoadfromStream' with the following error message:
"the data stream format is not recognised".
The executed code is
F := TFileStream.Create(FileName, fmOpenRead);
S := TMemoryStream.Create;
try
S.SetSize(F.Size + 2);
P := S.Memory;
Move(CrLf[1], P^, 2);
Inc(P, 2);
F.ReadBuffer(P^, F.Size);
MT.LoadFromStream(S, dfAny);
The file contains one line of text '123,"test description","F","T"'.
After the ReadBuffer P contains '123,"test description","F","T"r'.
Looking at the code in Bufdataset. and Bufdataset.TFpcBinaryDatapacketReader.RecognizeStream shows the code doing some strange things where it compares
#13#10'123,"test d' against FpcBinaryIdent = 'BinBufDataset';
this fails and it is all down hill from there.......
Any ideas, solutions, explanation, examples of using a LoadFromStream with BufDataset appreciated.
thanks, Ian.
Loesje:
LoadFromStream uses by default a binary format. You can add more formats by adding more formatter-units.
There is currently no formatter for csv files, but you can use the xml-format that Delphi's TClientDataset also uses by default. Add the 'xmldatapacketreader' to your program and it will recognize Delphi's xml format.
stonefull:
I'd use TSdfDataSet.
iru:
Gentlefolk,
Thanks for the responses.
May I ask why use 'TSdfDataSet' ?????
Ian
stonefull:
TSdfDataset can define commas as separator, like csv format. It's very simple.
Navigation
[0] Message Index
[#] Next page