Recent

Author Topic: TBufDataset with Invalid character on Post and crash  (Read 1525 times)

talisjonatas

  • New Member
  • *
  • Posts: 14
TBufDataset with Invalid character on Post and crash
« on: July 09, 2025, 11:06:24 pm »
Hi everyone,

I'm having an issue with TBufDataset (which does not happen with TMemDataset), where all string fields are saved with invalid characters after posting the record. Some fields are saved correctly, others are not.

Tested using Lazarus 4.0.

I've attached both a code snippet and a sample project to reproduce the issue.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.  i: integer;
  4. begin
  5.  i:= 0;
  6.  BufDataset1.Close;
  7.  BufDataset1.CreateDataset;
  8.  BufDataset1.Open;
  9.  
  10.  repeat
  11.   if not BufDataset1.IsEmpty then
  12.    BufDataset1.Append;
  13.   BufDataset1.Edit;
  14.  
  15.   BufDataset1.FieldByName('name').AsString:= 'Talis ' + IntToStr(i);
  16.   BufDataset1.FieldByName('lastname').AsString:= 'Gomes';
  17.  
  18.   BufDataset1.Post;
  19.  
  20.   inc(i)
  21.  until i > 5;
  22. end;  
  23.  


In attachment image the error and test project

Any suggestions or tips would be greatly appreciated.

Very thanks

Talis

Zvoni

  • Hero Member
  • *****
  • Posts: 3349
Re: TBufDataset with Invalid character on Post and crash
« Reply #1 on: July 10, 2025, 08:01:40 am »
I'm trying to wrap my mind around:
1) You close the (active?) Dataset
2) You create the Dataset anew using its FieldDefs?!?!??!
3) You open the Dataset
4) You check if the Dataset is NOT empty --> has content?!?!? Why?
5) If it has content start Append
6) No matter the result from step 5, you go into Edit-Mode?!?!??!

....this is some really borked code....
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

talisjonatas

  • New Member
  • *
  • Posts: 14
Re: TBufDataset with Invalid character on Post and crash
« Reply #2 on: July 10, 2025, 01:35:05 pm »
1) You close the (active?) Dataset
2) You create the Dataset anew using its FieldDefs?!?!??!
3) You open the Dataset
4) You check if the Dataset is NOT empty --> has content?!?!? Why?
5) If it has content start Append
6) No matter the result from step 5, you go into Edit-Mode?!?!??!

Hello,

I understand your concerns. The example is just an adaptation of a real code scenario. If you follow all the points you mentioned, the result will be exactly the same.

If there is a way to get around the problem I would be grateful for your help.

paweld

  • Hero Member
  • *****
  • Posts: 1596
Re: TBufDataset with Invalid character on Post and crash
« Reply #3 on: July 10, 2025, 01:49:42 pm »
Your example works fine for me, both in Lazarus 4.0/FPC 3.2.2 and Lazarus 4.99 (trunk)/FPC 3.2-fixes.
I am attaching another example, you can check if it works correctly for you.
Best regards / Pozdrawiam
paweld

talisjonatas

  • New Member
  • *
  • Posts: 14
Re: TBufDataset with Invalid character on Post and crash
« Reply #4 on: July 10, 2025, 04:53:42 pm »
Your example works fine for me, both in Lazarus 4.0/FPC 3.2.2 and Lazarus 4.99 (trunk)/FPC 3.2-fixes.
I am attaching another example, you can check if it works correctly for you.

I managed to understand the problem. It's a bug that happens if you click "Create Dataset" in Design Time, and it crashes.

Thank you very much for providing the demo, as it was the only way I could understand the problem.


 

TinyPortal © 2005-2018