Handling delta to apply key field changes to other delta

My app writes local data to Briefcase and then updates it on the server.
An autoinc key is generated in a table and then replaced on the server. I need to apply this key in Delta of other tables as foreign key.
I prefer to do this manually, rather than using the Master - Detail relationship.
Which event can I use in the master table, to get the Delta with the key value before and after it is modified on the server?
Could you give some example of how to query the value before and after ApplyUpdates and how to modify the Delta of the detail table to apply the new key value?

Hi,

check TDADataTable.MergeDelta method. it uses OnBeforeMergeDelta & OnAfterMergeDelta events.

use the OnBeforeMergeDelta event. Delta will contain both values - old and new ones.

something like

old_value := mastertable.Delta.Changes[x].OldValueByName['ID'].
new_value := mastertable.Delta.Changes[x].NewValueByName['ID'].
...
detail.FieldByName['masterid'].AsInteger := new_value;
1 Like

Nice! It works!
Thank you.