Recent

Author Topic: TBufDataset+TDBGrid basic application problem (new records disappear)  (Read 640 times)

e5431

  • Newbie
  • Posts: 2
Hi everyone!
I'm trying to make a simple BufDataset application for storing a name list in a BufDataset in Lazarus 4.2+FPC 3.2.2 on Win 10 x64.
I put  TBufDataset, TDataSource, TDBGrid and TDBNavigator on my form with DataSet and DataSource properties filled.
When I run the application and click Insert button and type in a name, press Enter and then click Post, the name disappears from the grid (I've attached a gif for illustration).
If I keep adding new records, the new ones disappear after Post as well.
But sometimes some of them appear in the grid again.

When closing the application I get
'External: ACCESS VIOLATION' with message
Access violation reading from address $FFFFFFFFFFFFFFFF.

I can't understand what I do wrong. There is no code at all!
I recall when I wrote a similar app in Dephi 7, it worked fine.

Please help me to fix the issue.

PS: the archive with Lazarus project attached
« Last Edit: March 21, 2026, 03:31:46 pm by e5431 »

Nimbus

  • Jr. Member
  • **
  • Posts: 88
Re: TBufDataset+TDBGrid basic application problem (new records disappear)
« Reply #1 on: March 21, 2026, 12:06:55 am »
Hi, I've tried your project (built using Lazarus 4.6 / FPC trunk under Linux) and it seems to be fine, can't see any problem.
Insert, edit, delete, post all work as expected.
Perhaps something's up with specific FPC/Laz version?

wp

  • Hero Member
  • *****
  • Posts: 13502
Re: TBufDataset+TDBGrid basic application problem (new records disappear)
« Reply #2 on: March 21, 2026, 01:36:04 am »
Running your demo on Laz/main+FPC3.2.2 (32-bit) on Windows 11 I do get the same issue: only empty cells in the grid.

Your code contains persistent fields and designtime-created index defs. I am aware that that Lazarus/FPC are doing a bad job with databases at designtime. Maybe this has improved with FPC-trunkl because Nimbus does not see this issue (TBufDataset resides in FPC, not in Lazarus).

Usually it helps to avoid designtime operations with databases and do everything at runtime. I deleted the persistent field and the indexdefs - and suffered from some Lazarus crashes along the way. The better way probably is to delete the BufDataset altogether and just add a default one again. Then, use the OnCreate handler of the form to define the fields and indexes by code:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   BufDataset1.FieldDefs.Add('Name', ftString, 100);
  4.   Bufdataset1.IndexDefs.Add('ASCENDING_ORDER', 'Name', []);
  5.   Bufdataset1.IndexDefs.Add('DESCENDING_ORDER', 'Name', [ixDescending]);
  6.   BufDataset1.IndexName := 'DESCENDING_ORDER';
  7.   BufDataset1.CreateDataset;
  8.   BufDataset1.Open;
  9.   DBGrid1.Columns[0].Width := 100;
  10. end;
This modification is running fine.

e5431

  • Newbie
  • Posts: 2
Re: TBufDataset+TDBGrid basic application problem (new records disappear)
« Reply #3 on: March 21, 2026, 04:19:53 am »
wp: Thank you! It really works.
I hope it will be possible someday to do the things in design time without problems.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1258
Re: TBufDataset+TDBGrid basic application problem (new records disappear)
« Reply #4 on: March 21, 2026, 04:48:33 am »
Running your demo on Laz/main+FPC3.2.2 (32-bit) on Windows 11 I do get the same issue: only empty cells in the grid.

Your code contains persistent fields and designtime-created index defs. I am aware that that Lazarus/FPC are doing a bad job with databases at designtime. Maybe this has improved with FPC-trunkl because Nimbus does not see this issue (TBufDataset resides in FPC, not in Lazarus).

Usually it helps to avoid designtime operations with databases and do everything at runtime. I deleted the persistent field and the indexdefs - and suffered from some Lazarus crashes along the way. The better way probably is to delete the BufDataset altogether and just add a default one again. Then, use the OnCreate handler of the form to define the fields and indexes by code:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   BufDataset1.FieldDefs.Add('Name', ftString, 100);
  4.   Bufdataset1.IndexDefs.Add('ASCENDING_ORDER', 'Name', []);
  5.   Bufdataset1.IndexDefs.Add('DESCENDING_ORDER', 'Name', [ixDescending]);
  6.   BufDataset1.IndexName := 'DESCENDING_ORDER';
  7.   BufDataset1.CreateDataset;
  8.   BufDataset1.Open;
  9.   DBGrid1.Columns[0].Width := 100;
  10. end;
This modification is running fine.

Interesting.

 

TinyPortal © 2005-2018