Forum > Database
BufDataSet can't open .bds file
QikFix:
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---local := local + 'file.bds'; if FileExists(local) then DeleteFile(pChar(local)); bds1.SaveToFile(local, true); BufDataset1.LoadFromFile(local);
And this way:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---local := local + 'file.bds'; if FileExists(local) then DeleteFile(pChar(local)); bds1.SaveToFile(local); BufDataset1.LoadFromFile(local);
i also tried this way:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
--- Quote from: QikFix on December 29, 2016, 02:03:54 am ---The data-stream format is not reconized.
--- End quote ---
i am unable to re-create that error.
--- Quote ---I tried this way:
--- End quote ---
That part does not work because there is code missing.
--- Quote ---And this way:
--- End quote ---
That part does not work either because there is code missing.
--- Quote ---i also tried this way:
--- End quote ---
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.
--- End quote ---
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
--- Quote from: molly on December 29, 2016, 03:01:04 am ---Please refrain from these kind of fishing expeditions and post some actual code that is compilable.
--- End quote ---
Molly, this is the entire function code. Thanks for the advise.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
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:
--- Quote from: molly on December 29, 2016, 03:25:59 am ---Thank you. Now i can see you did not use two bufdataset's but a tmemdataset.
--- End quote ---
OMG, i didn't see that... Thanks a lot!
--- Quote from: molly on December 29, 2016, 03:25:59 am ---But, who, what and where is BufDataSet1 ? I can only see that you attempt to load it on line 95.
--- End quote ---
I created BufDataSet1 by dragging from Data Acess, visually.
Molly, thanks again!
Navigation
[0] Message Index
[#] Next page