BufDataset and LoadFromStream problem lazarus / 31-LCL ---------------------------------------------------------------------- iru · 2010-05-25 21:04 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 · 2010-05-27 09:13 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 · 2010-05-27 12:32 I'd use TSdfDataSet. ---------------------------------------------------------------------- iru · 2010-05-27 19:09 Gentlefolk, Thanks for the responses. May I ask why use 'TSdfDataSet' ????? Ian ---------------------------------------------------------------------- stonefull · 2010-05-28 04:50 TSdfDataset can define commas as separator, like csv format. It's very simple. ---------------------------------------------------------------------- iru · 2010-05-29 06:25 Thanks for the response. All goes well up to a point. I can load the contents of a file (can see it in an associated DBGrid). However when I try  SdfDataSet.FieldByName('Name').AsString a 'field not known' exception occurs. The field is there, it is defined at design time. Looking at the code in dtaset.inc it would appear that no fields are defined. I will attempt to dynamically define the fields and see what happens. Ian ---------------------------------------------------------------------- stonefull · 2010-05-29 07:05 TSdfDataset define field names as Field1, Field2, Field3, etc... You can't modify them. Try SdfDataSet.FieldByName('Field1').AsString I wrote a post (in Portuguese) about this: http://professorcarlos.blogspot.com/2010/03/lazarus-tratamento-de- arquivos-texto.html ---------------------------------------------------------------------- tatamata · 2010-05-29 12:10 See http://wiki.lazarus.freepascal.org/How_to_write_in-memory_database _applications_in_Lazarus/FPC#Saving_MemDatasets_To_Persistent_Files ---------------------------------------------------------------------- iru · 2010-05-29 18:00 Gentlefolk, Thank you, abbrigado (my one word of Portugese learned on a breif vizit to Mozambique (spelling ???)). Things are now working OK. Ian ---------------------------------------------------------------------- typo · 2010-05-29 18:04 It's "obrigado".