BufDataSet can't open .bds file lazarus / 63-Database ---------------------------------------------------------------------- QikFix · 2016-12-29 01:03 Hello guys; So, i created a TBufDataSet to store data collected from a text file. I could save it, but when i tried to load the file in another TBufDataSet, it's show the following error message: The data-stream format is not reconized. I tried this way: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i local := local + 'file.bds'; if FileExists(local) then  DeleteFile(pChar(local)); bds1.SaveToFile(local, true); BufDataset1.LoadFromFile(local);  And this way: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i local := local + 'file.bds'; if FileExists(local) then  DeleteFile(pChar(local) ); bds1.SaveToFile(local); BufDataset1.LoadFromFile(local); i also tried this way: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i local := local + 'file.bds'; if FileExists(local) then  DeleteFile(pChar(local)); bds1.SaveToFile(local, true); BufDataset1.FileName := local;BufDataset1.Open;  No sucess at all. The 'local' var contains the full path to the file. I saw a similar post here in the forum: http://forum.lazarus.freepascal.org/index.php?topic=33629.0 Didn't work for me. I'm using Windows 10 Pro 64 bits and the version of Lazarus is FPC 3.0 (Sorry my English) ---------------------------------------------------------------------- molly · 2016-12-29 02:01 Quote from: QikFix on December 29, 2016, 02:03:54 amThe data-stream format is not reconized. i am unable to re-create that error. QuoteI tried this way: That part does not work because there is code missing. QuoteAnd this way: That part does not work either because there is code missing. Quotei also tried this way: That part also does not work because there is code missing. QuoteI saw a similar post here in the forum: http://forum.lazarus.freepascal.org/index.php?topic=33629.0 Didn't work for me. The code shown in that post, combined with the corrections that were posted works perfectly ok for me. If i rewrite that example to match your situation that also works perfectly ok for me. Please, next time, refrain from these kind of fishing expeditions and post some actual code that is compilable. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TakeThree;var  bds1          : TBufDataSet;  BufDataSet1   : TBufDataSet;  local         : string = '';begin  bds1 := TBufDataSet.Create(nil);  bds1.FieldDefs.Add('Name',ftString,20);    bds1.CreateDataSet;  bds1.Append;  bds1.Fields[0].value := 'Dodo';  bds1.Post;  WriteLn('Before Save :', bds1.Fields.FieldByName('Name').AsString);     local := local + 'file.bds';  if FileExists(local) then DeleteFile(local);  bds1.SaveToFile(local);   BufDataSet1 := TBufDataSet.Create(nil);  BufDataSet1.LoadFromFile(local);  Writeln('After Load :', BufDataSet1.Fields.FieldByName('Name').AsString);  BufDataSet1.Free;   bds1.free;end; ---------------------------------------------------------------------- QikFix · 2016-12-29 02:18 Quote from: molly on December 29, 2016, 03:01:04 amPlease refrain from these kind of fishing expeditions and post some actual code that is compilable. Molly, this is the entire function code. Thanks for the advise. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmPrincipal.Executar;var  i: integer;  sr: TSearchRec;  local, line, nameD, rankD, typeD, dnaD, dnaparentD: string;  sl1: TStringList;  bds1: TMemDataSet;  txt: TextFile;begin  local := ExtractFilePath(Application.ExeName) + 'dnas\';   if SetCurrentDir(local) then  begin    memo1.lines.Clear;     if FindFirst('*.txt', faAnyFile, sr) = 0 then    begin      sl1 := TStringList.Create;       bds1 := TMemDataSet.Create(self);       bds1.FieldDefs.Add('NAME', ftString, 50);      bds1.FieldDefs.Add('RANK', ftString, 10);      bds1.FieldDefs.Add('TYPE', ftString, 3);      bds1.FieldDefs.Add('DNA', ftString, 2);      bds1.FieldDefs.Add('DNA_PARENT', ftString, 1);       bds1.CreateTable;      bds1.Open;       repeat        memo1.lines.Add('Buscando arquivo ' + sr.Name);        sl1.Add(sr.Name);        SendMessage(memo1.Handle, WM_VSCROLL, SB_BOTTOM, 0);      until FindNext(sr) <> 0;       for i := 0 to sl1.count - 1 do      begin        memo1.lines.Add('Lendo o arquivo ' + sl1[i]);        SendMessage(memo1.Handle, WM_VSCROLL, SB_BOTTOM, 0);         AssignFile(txt, sl1[i]);        Reset(txt);         while not eof(txt) do        begin          readln(txt, line);           nameD := Copy(line, 0, pos('mon', line) + 2);          rankD := Copy(ExtractFileNameWithoutExt(sl1[i]), 9, 1);           case rankD[1] of            'r': rankD := '0';            'c': rankD := '1';          'u': rankD := '2';            'm': rankD := '3';          end;         typeD := Copy(ExtractFileNameWithoutExt(sl1[i]), 5, 3);         case typeD[3] of            'c': typeD := 'A';            't': typeD := 'D';            'r': typeD := 'I';          end;           dnaD := iif(rankD = 'mega', '??', iif(rankD = 'rook', Copy(line, pos('mon', line) + 4, 2), Copy(line, pos('mon', line) + 6, 2)));          dnaparentD := iif(rankD = 'rook', '?', Copy(line, pos('mon', line) + 4, 1));           bds1.Append;          bds1.FieldByName('NAME').AsString := nameD;          bds1.FieldByName('RANK').AsString := rankD;          bds1.FieldByName('TYPE').AsString := typeD;          bds1.FieldByName('DNA').AsString := dnaD;          bds1.FieldByName('DNA_PARENT').AsString := dnaparentD;          bds1.Post;         end;       end;       if not bds1.IsEmpty then    begin        memo1.lines.Add('');        memo1.lines.Add('Criando o arquivo resultante ' + local + 'dnas_dw2');        SendMessage(memo1.Handle, WM_VSCROLL, SB_BOTTOM, 0);         local := local + 'dnas_dw2.bds';         if FileExists(local) then          DeleteFile(pChar(local));         bds1.SaveToFile(local);         BufDataset1.LoadFromFile(local);       end      else ShowMessage('ERRO: Nenhum dado encontrado.');       FreeAndNil(sl1);    FreeAndNil(bds1);     end;   end  else begin    ShowMessage('ERRO: Pasta não encontrada' + #13#10 + 'Caminho: ' + local);    Application.Terminate;  end;end; ---------------------------------------------------------------------- molly · 2016-12-29 02:25 Thank you. Now i can see you did not use two bufdataset's but a tmemdataset. But,  who, what and where is BufDataSet1 ? I can only see that you attempt to load it on line 95. ---------------------------------------------------------------------- QikFix · 2016-12-29 02:32 Quote from: molly on December 29, 2016, 03:25:59 amThank you. Now i can see you did not use two bufdataset's but a tmemdataset. OMG, i didn't see that... Thanks a lot! Quote from: molly on December 29, 2016, 03:25:59 amBut,  who, what and where is BufDataSet1 ? I can only see that you attempt to load it on line 95. I created BufDataSet1 by dragging from Data Acess, visually. Molly, thanks again! ---------------------------------------------------------------------- molly · 2016-12-29 02:44 Thank you QikFix, as now i was able to re-create your error  Seems to me hat files created with TMemDataSet and TBufDataSet are not compatible with each other. As long as you use the same class for both 'datasets' you should be good to go. But you already got that part, i guess  PS: sorry in case my first reaction sounded to harsh, i just noticed it was your first post (i overlooked). ---------------------------------------------------------------------- LacaK · 2016-12-29 07:50 Quote from: molly on December 29, 2016, 03:44:37 amSeems to me hat files created with TMemDataSet and TBufDataSet are not compatible with each other. Right ---------------------------------------------------------------------- Thaddy · 2016-12-29 11:03 And it is because of their history.... Can do, won't do. Delphi is compatible? for those two? But anyway it can be done but which way would you prefer? What is "the best" format? Why is it that plain  SQL won't do what I say over multiple dialects?