Forum > Databases
TBufDataset.First issue.
dmitryb:
Lazarus 2.2.4 (rev lazarus_2_2_4) FPC 3.2.2 x86_64-win64-win32/win64
Next code in Lazarus 2.2.4 shows empty string.
--- 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 TForm1.Button4Click(Sender: TObject);var s: String;begin BufDataset1 := TBufDataset.Create(Self); BufDataset1.FieldDefs.Add('Str5Field', ftString, 5, -1, False, False, 0, CP_UTF8); BufDataset1.CreateDataset; BufDataset1.Append; BufDataset1.FieldByName('Str5Field').AsString := 'ABCDEFG'; BufDataset1.Post; BufDataset1.First; s := VarToStr(BufDataset1.FieldByName('Str5Field').AsVariant); ShowMessage(s);end;
Is this a feature or a bug?
egsuh:
Why not simply
s := BufDataset1.FieldByName('Str5Field').AsString;
?
Zvoni:
--- Quote from: egsuh on January 25, 2023, 04:26:46 am ---Why not simply
s := BufDataset1.FieldByName('Str5Field').AsString;
?
--- End quote ---
Same issue.
I can confirm
--- 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";}};} ---program Project1;Uses bufdataset,db; Var s:String; bd:TBufDataset; begin bd:=TBufDataset.Create(Nil); bd.FieldDefs.Add('Str5Field',ftString,5,-1,False,False,0,CP_UTF8); bd.CreateDataset; Writeln('RecCount=',bd.RecordCount); bd.Append; bd.FieldByName('Str5Field').AsString:='ABCDEFG'; bd.Post; Writeln('RecCount=',bd.RecordCount); Writeln('BOF=',bd.BOF,' - EOF=',bd.EOF); s:=bd.Fieldbyname('Str5Field').AsString; Writeln('recNo=',bd.RecNo,' - s=',s); bd.First; Writeln('BOF=',bd.BOF,' - EOF=',bd.EOF); s:=bd.Fieldbyname('Str5Field').AsString; Writeln('recNo=',bd.RecNo,' - s=',s); bd.Last; Writeln('BOF=',bd.BOF,' - EOF=',bd.EOF); s:=bd.Fieldbyname('Str5Field').AsString; Writeln('recNo=',bd.RecNo,' - s=',s); bd.First; Writeln('BOF=',bd.BOF,' - EOF=',bd.EOF); s:=bd.Fieldbyname('Str5Field').AsString; Writeln('recNo=',bd.RecNo,' - s=',s);end.
Result
--- Quote ---RecCount=0
RecCount=1
BOF=FALSE - EOF=FALSE
recNo=1 - s=ABCDEFG
BOF=TRUE - EOF=FALSE
recNo=1 - s=
BOF=FALSE - EOF=TRUE
recNo=1 - s=ABCDEFG
BOF=TRUE - EOF=FALSE
recNo=1 - s=
--- End quote ---
TRon:
In addition to Zvoni's findings:
- it leaks memory
- it creates an access violation when not using a exception block to free the instantiated class.
I get very strange output characters instead of receiving empty strings (unlike Zvoni)
Zvoni:
--- Quote from: TRon on January 25, 2023, 09:46:15 am ---In addition to Zvoni's findings:
- it leaks memory
- it creates an access violation when not using a exception block to free the instantiated class.
--- End quote ---
Yes, it's the reason why i left out bd.free in above code (and i don't care about memory-leaks when just testing around and it's basically the end of the program anyway)
Something that baffles me: RecCount is 1, shouldn't BOF and EOF both be true, irrespective if i move Next, Prior, First or Last??
Navigation
[0] Message Index
[#] Next page