* * *

Author Topic: BufDataSet can't open .bds file  (Read 1072 times)

QikFix

  • Newbie
  • Posts: 3
BufDataSet can't open .bds file
« on: December 29, 2016, 02:03:54 am »
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]
  1. local := local + 'file.bds';
  2.  
  3. if FileExists(local) then
  4.   DeleteFile(pChar(local));
  5.  
  6. bds1.SaveToFile(local, true);
  7.  
  8. BufDataset1.LoadFromFile(local);
  9.  

And this way:
Code: Pascal  [Select]
  1. local := local + 'file.bds';
  2.  
  3. if FileExists(local) then
  4.   DeleteFile(pChar(local));
  5.  
  6. bds1.SaveToFile(local);
  7.  
  8. BufDataset1.LoadFromFile(local);
  9.  

i also tried this way:
Code: Pascal  [Select]
  1. local := local + 'file.bds';
  2.  
  3. if FileExists(local) then
  4.   DeleteFile(pChar(local));
  5.  
  6. bds1.SaveToFile(local, true);
  7.  
  8. BufDataset1.FileName := local;
  9. BufDataset1.Open;
  10.  

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

  • Hero Member
  • *****
  • Posts: 1393
Re: BufDataSet can't open .bds file
« Reply #1 on: December 29, 2016, 03:01:04 am »
The data-stream format is not reconized.
i am unable to re-create that error.

Quote
I tried this way:
That part does not work because there is code missing.

Quote
And this way:
That part does not work either because there is code missing.

Quote
i also tried this way:
That part also does not work because there is code missing.

Quote
I 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]
  1. procedure TakeThree;
  2. var
  3.   bds1          : TBufDataSet;
  4.   BufDataSet1   : TBufDataSet;
  5.   local         : string = '';
  6. begin
  7.   bds1 := TBufDataSet.Create(nil);
  8.   bds1.FieldDefs.Add('Name',ftString,20);  
  9.   bds1.CreateDataSet;
  10.   bds1.Append;
  11.   bds1.Fields[0].value := 'Dodo';
  12.   bds1.Post;
  13.   WriteLn('Before Save :', bds1.Fields.FieldByName('Name').AsString);  
  14.  
  15.   local := local + 'file.bds';
  16.   if FileExists(local) then DeleteFile(local);
  17.   bds1.SaveToFile(local);
  18.  
  19.   BufDataSet1 := TBufDataSet.Create(nil);
  20.   BufDataSet1.LoadFromFile(local);
  21.   Writeln('After Load :', BufDataSet1.Fields.FieldByName('Name').AsString);
  22.   BufDataSet1.Free;
  23.  
  24.   bds1.free;
  25. end;
  26.  
« Last Edit: December 29, 2016, 03:17:23 am by molly »

QikFix

  • Newbie
  • Posts: 3
Re: BufDataSet can't open .bds file
« Reply #2 on: December 29, 2016, 03:18:21 am »
Please 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]
  1. procedure TfrmPrincipal.Executar;
  2. var
  3.   i: integer;
  4.   sr: TSearchRec;
  5.   local, line, nameD, rankD, typeD, dnaD, dnaparentD: string;
  6.   sl1: TStringList;
  7.   bds1: TMemDataSet;
  8.   txt: TextFile;
  9. begin
  10.   local := ExtractFilePath(Application.ExeName) + 'dnas\';
  11.  
  12.   if SetCurrentDir(local) then
  13.   begin
  14.     memo1.lines.Clear;
  15.  
  16.     if FindFirst('*.txt', faAnyFile, sr) = 0 then
  17.     begin
  18.       sl1 := TStringList.Create;
  19.  
  20.       bds1 := TMemDataSet.Create(self);
  21.  
  22.       bds1.FieldDefs.Add('NAME', ftString, 50);
  23.       bds1.FieldDefs.Add('RANK', ftString, 10);
  24.       bds1.FieldDefs.Add('TYPE', ftString, 3);
  25.       bds1.FieldDefs.Add('DNA', ftString, 2);
  26.       bds1.FieldDefs.Add('DNA_PARENT', ftString, 1);
  27.  
  28.       bds1.CreateTable;
  29.       bds1.Open;
  30.  
  31.       repeat
  32.         memo1.lines.Add('Buscando arquivo ' + sr.Name);
  33.         sl1.Add(sr.Name);
  34.         SendMessage(memo1.Handle, WM_VSCROLL, SB_BOTTOM, 0);
  35.       until FindNext(sr) <> 0;
  36.  
  37.       for i := 0 to sl1.count - 1 do
  38.       begin
  39.         memo1.lines.Add('Lendo o arquivo ' + sl1[i]);
  40.         SendMessage(memo1.Handle, WM_VSCROLL, SB_BOTTOM, 0);
  41.  
  42.         AssignFile(txt, sl1[i]);
  43.         Reset(txt);
  44.  
  45.         while not eof(txt) do
  46.         begin
  47.           readln(txt, line);
  48.  
  49.           nameD := Copy(line, 0, pos('mon', line) + 2);
  50.           rankD := Copy(ExtractFileNameWithoutExt(sl1[i]), 9, 1);
  51.  
  52.           case rankD[1] of
  53.             'r': rankD := '0';
  54.             'c': rankD := '1';
  55.             'u': rankD := '2';
  56.             'm': rankD := '3';
  57.           end;
  58.  
  59.           typeD := Copy(ExtractFileNameWithoutExt(sl1[i]), 5, 3);
  60.  
  61.           case typeD[3] of
  62.             'c': typeD := 'A';
  63.             't': typeD := 'D';
  64.             'r': typeD := 'I';
  65.           end;
  66.  
  67.           dnaD := iif(rankD = 'mega', '??', iif(rankD = 'rook', Copy(line, pos('mon', line) + 4, 2), Copy(line, pos('mon', line) + 6, 2)));
  68.           dnaparentD := iif(rankD = 'rook', '?', Copy(line, pos('mon', line) + 4, 1));
  69.  
  70.           bds1.Append;
  71.           bds1.FieldByName('NAME').AsString := nameD;
  72.           bds1.FieldByName('RANK').AsString := rankD;
  73.           bds1.FieldByName('TYPE').AsString := typeD;
  74.           bds1.FieldByName('DNA').AsString := dnaD;
  75.           bds1.FieldByName('DNA_PARENT').AsString := dnaparentD;
  76.           bds1.Post;
  77.  
  78.         end;
  79.  
  80.       end;
  81.  
  82.       if not bds1.IsEmpty then
  83.       begin
  84.         memo1.lines.Add('');
  85.         memo1.lines.Add('Criando o arquivo resultante ' + local + 'dnas_dw2');
  86.         SendMessage(memo1.Handle, WM_VSCROLL, SB_BOTTOM, 0);
  87.  
  88.         local := local + 'dnas_dw2.bds';
  89.  
  90.         if FileExists(local) then
  91.           DeleteFile(pChar(local));
  92.  
  93.         bds1.SaveToFile(local);
  94.  
  95.         BufDataset1.LoadFromFile(local);
  96.  
  97.       end
  98.       else ShowMessage('ERRO: Nenhum dado encontrado.');
  99.  
  100.       FreeAndNil(sl1);
  101.       FreeAndNil(bds1);
  102.  
  103.     end;
  104.  
  105.   end
  106.   else begin
  107.     ShowMessage('ERRO: Pasta não encontrada' + #13#10 + 'Caminho: ' + local);
  108.     Application.Terminate;
  109.   end;
  110. end;
  111.  

molly

  • Hero Member
  • *****
  • Posts: 1393
Re: BufDataSet can't open .bds file
« Reply #3 on: December 29, 2016, 03:25:59 am »
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

  • Newbie
  • Posts: 3
Re: BufDataSet can't open .bds file
« Reply #4 on: December 29, 2016, 03:32:24 am »
Thank you. Now i can see you did not use two bufdataset's but a tmemdataset.

OMG, i didn't see that... Thanks a lot!

But,  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

  • Hero Member
  • *****
  • Posts: 1393
Re: BufDataSet can't open .bds file
« Reply #5 on: December 29, 2016, 03:44:37 am »
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  :D

PS: sorry in case my first reaction sounded to harsh, i just noticed it was your first post (i overlooked).
« Last Edit: December 29, 2016, 03:53:27 am by molly »

LacaK

  • Hero Member
  • *****
  • Posts: 521
Re: BufDataSet can't open .bds file
« Reply #6 on: December 29, 2016, 08:50:27 am »
Seems to me hat files created with TMemDataSet and TBufDataSet are not compatible with each other.
Right  :)

Thaddy

  • Hero Member
  • *****
  • Posts: 2997
Re: BufDataSet can't open .bds file
« Reply #7 on: December 29, 2016, 12:03:39 pm »
And it is because of their history.... :P 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?

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus