Forum > Databases
TBufDataset.First issue.
TRon:
--- Quote from: Zvoni on January 25, 2023, 11:32:31 am ---BOF/EOF will only be set to True if you try to MOVE BEYOND the First/Last record
--- End quote ---
Ah, yes !!. That was the conclusion from the conversation I remembered as well. Thx for the refresh guys/galls !
Thaddy:
An old example from 2016 written by me and already on this forum:
--- 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";}};} ---{$apptype console}{$mode objfpc}uses db,BufDataset;var BufDb:TBufDataset;begin BufDb:=TBufDataset.Create(nil); try BufDb.FieldDefs.Add('NAME',ftString,20); BufDb.FieldDefs.Add('NUM',ftinteger); BufDb.FieldDefs.Add('NUM2',ftInteger); BufDb.CreateDataSet; BufDb.Open; BufDb.Append; BufDb.FieldByName('NAME').Value:='Free'; BufDb.Post; BufDb.Append; BufDb.FieldByName('NAME').Value:='Pascal'; BufDb.Post; BufDb.SaveToFile('BufDb.txt'); finally BufDb.Close; BufDb.Free; end; // now, open.. BufDb := TBufDataset.Create(nil); try BufDb.LoadFromFile('BufDb.txt'); BufDb.Open; BufDb.First; Writeln(BufDb.FieldByName('NAME').Value); finally BufDb.Close; BufDb.Free; end; end.
It seems to me that just the call to open is the culprit.
https://forum.lazarus.freepascal.org/index.php/topic,33508.msg217317.html#msg217317
Zvoni:
--- Quote from: Thaddy on January 25, 2023, 02:08:55 pm ---An old example from 2016 written by me and already on this forum:
--- 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";}};} ---{$apptype console}{$mode objfpc}uses db,BufDataset;var BufDb:TBufDataset;begin BufDb:=TBufDataset.Create(nil); try BufDb.FieldDefs.Add('NAME',ftString,20); BufDb.FieldDefs.Add('NUM',ftinteger); BufDb.FieldDefs.Add('NUM2',ftInteger); BufDb.CreateDataSet; BufDb.Open; BufDb.Append; BufDb.FieldByName('NAME').Value:='Free'; BufDb.Post; BufDb.Append; BufDb.FieldByName('NAME').Value:='Pascal'; BufDb.Post; BufDb.SaveToFile('BufDb.txt'); finally BufDb.Close; BufDb.Free; end; // now, open.. BufDb := TBufDataset.Create(nil); try BufDb.LoadFromFile('BufDb.txt'); BufDb.Open; BufDb.First; Writeln(BufDb.FieldByName('NAME').Value); finally BufDb.Close; BufDb.Free; end; end.
It seems to me that just the call to open is the culprit.
https://forum.lazarus.freepascal.org/index.php/topic,33508.msg217317.html#msg217317
--- End quote ---
No, it was the FieldNo in the (overloaded) Add-Function. OP (and myself) missed that FieldNo is 1-based. OP used for that sample FieldNo=0
Thaddy:
I wouldn't call it no!, because if you want to read the first entry, first will do nicely. Hence that old example.
It is cleaner and much easier than the bull dung above.
egsuh:
In Zvony’s example, calling RecNo might have moved cursor beyond last record.
Navigation
[0] Message Index
[*] Previous page