How can I get TClientDataset changes to another TClientDataset?
If you have the original CDS1 ClientDataSet, you can copy the changed entries to the second CDS2 ClientDataSet by doing
if CDS1.ChangeCount > 0 then
CDS2.Data := CDS1.Delta;
As you will see, if you try this, it will give you a "before" entry and one with the changes. This may not necessarily be what you want - to be honest, you would be best off reading Whipple's article posted in the comment and on OLH to get the exact result you might want to achieve. The point is that all the necessary information is in the original CDS until you clear it (by calling ApplyUpdates () - after that, if it succeeds, the change log is empty).
If you look at the lines in CDS2, it is not immediately obvious how you indicate whether a particular field contains a modified value and how you distinguish the one that does from the one that is only empty. Istra had a very good post for quite some time on one of the Borland NTTP newsgroups by their Mark Edington, I think explaining how to do that. Basically, it's a matter of evaluating VarIsClear on the NewValue property field:
if VarIsClear(CDS2.Fields[i].NewValue) then
// means Fields[i] does not have a changed value
By the way, since you can save the state of the CDS to XML, you can use XML manipulation for example. with a DOM parser like embedded Windows (see MSXML.Pas) to easily do many of the things that make the TDataSet paradigm difficult to use.
source to share