0

I got a TClientDataset that contains data from several tables. When I apply updates on this dataset it might get out of sync.

I'll give you one example:

In the table to update i got an id called "Client_id". The clientdataset also contains a value "Client_name" that is fetched from a "Client" table and displayed in the GUI.

Then I change the "Client_id" in my table and do an apply updates on the table the "Client_name" field in my dataset suddenly is out of sync. This is naturally because the clientdataset has not been refreshed.

Now I could do a clientdataet.refresh on the afterpost event, but then the cursor on the dataset jumps to the first record, and I loose my pointer to the updated record.

Anyone got a clue on how to solve this?

Øystein
  • 1,163
  • 1
  • 12
  • 23

2 Answers2

0

You should give RefreshRecord a try.

Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
  • I tried this at first, but got some runtime error messages. I think those messages as something else entirely, but because of shortage of time I did not have the time to debug it. I will have to give it another go once I find the time. Will accept your answer then, if I get it to work. – Øystein Oct 08 '12 at 06:34
0

set poPropogateChanges for your provider and assign any new field values in AfterUpdateRecord event handler

  • I do use this event to get back the PK after it has been inserted. It might also work for refreshing the values, but in my opinion, it could not be the most efficient method? I mean it would require quite a lot of maintenance in tables with many data fields. As a temporary solution I did a normal refresh, then used the dataset's index to move the pointer to the correct location afterwards. Not the best solution I know, but as mentioned I haven't got the time to look more closely at it for now. Will update this question as soon as I have time to dig into it more. – Øystein Oct 08 '12 at 06:39
  • in fact it is MORE efficient than doing another roundtrip (RefreshRecord or Refresh which is overkill) to appserver. actually that's exactly how mine TVDataSetProvider implemented poAutoRefresh support – Vladimir Ulchenko Oct 09 '12 at 07:11