Author Topic: fpjsondataset - unexpected fickle behaviour upon "Insert" new record  (Read 823 times)


  • Jr. Member
  • **
  • Posts: 86

I have been working through an unexpected behavior sometimes encountered when adding/ INSERT-ing a new record.

It appears to happen when the DBGrid Database cursor is on any other record than the first record showing in a DBGrid.

Attached is a working example project. The following explanation uses file: trial_0001.json

The use of the DBNavigator INSERT button causes a new record to be generated, and no matter where the database cursor is, it appears at the top, and initially as a full duplicate of the database's original first record.

If you attempt to enter (even first using the EDIT button to initiate) filling out the new record it disappears from view.

After first using the + INSERT button you have to immediately use the tick POST button, then you can successfully enter the record to add or edit information. At that point the (bogus) duplicate information from the first record disappears, and leaves you with pristine empty fields to use.

However, as you edit from left to right in the record's entry in the DBGrid, each previous field disappears as you enter the next.

Then  after you POST, all the new information/data re-appears correctly.

We can live with this procedure (immediately POST-ing a new record first before entering data)  - but I was thinking that it may flag other underlying problems, so thought to clear it all here first.

2. I open the JSON file(s) using:


3. I found it was unwise to simply save to file responding to the / using the DataSource's OnDataChange event as you may end up with a stripped down skeletal JSON file overwriting your data on disk, during the transition of opening the next JSON file. Instead, manually in response to a button click I use:

   FDataset.SaveToFile(global_FileName, true);

I don't know if there is anything else I should be doing?

The following stream of images (attached as: images-for-forum.7z) illustrate the problem. And the image titles summarize the situation...







Any further advice would be appreciated please.

Lazarus 1.8.0 r56594 FPC 3.0.4 x86_64-win64-win32/win64


« Last Edit: June 26, 2018, 04:58:21 am by PaulANormanNZ »