Delphi – How to convert TCLIENTDATASET to another TCLIENTDATASET?

How to get changes from TClientDataset?

I have a TClientDataset called GetDataset and I have a grid. I want to make changes in a new TClientDataset called ChangeDataset.

How can I do it To this point?

If you source ClientDataSet CDS1, you should be able to copy the changed records to the second ClientDataSet CDS2

if CDS1.ChangeCount> 0 then 
CDS2.Data := CDS1.Delta;

As you will As you can see, it will provide you with “before” records and records with changes. This may not necessarily be what you want – frankly, you’d better read the reviews and Whipple articles published in OLH to get The exact result you may wish to achieve. The key is that all the information you need is in the source CDS until you clear it (by calling ApplyUpdates()-afterwards, if successful, the change log is empty).

If you look at the lines in CDS2, you don’t know how to tell whether a particular field contains a changed value, and how to distinguish a blank one. A long time ago, Istr was in a Borland in his Mark Terdington There is a very good post in the NTTP newsgroup, I think, explaining how to do this. Basically, this is a question of evaluating VarIsClear on the NewValue property of the field:

if VarIsClear(CDS2.Fields[i].NewValue) then 
// means Fields[i] does not have a changed value

By the way, because you can save the state of CDS It is XML, so you can use XML operations. For example, using a DOM parser, such as the built-in Windows (see MSXML.Pas), can easily accomplish many troublesome things using the TDataSet example.

How to get changes from TClientDataset?

I have a TClientDataset called GetDataset and I have a grid. I want to make changes in a new TClientDataset called ChangeDataset.

How can I do it To this point?

If you source ClientDataSet CDS1, you should be able to copy the changed records to the second ClientDataSet CDS2 by executing

if CDS1.ChangeCount> 0 then 
CDS2.Data := CDS1.Delta;

As you will see, it will provide you with “before “Records and records with changes. This may not necessarily be what you want – frankly, you’d better read the comments and Whipple articles published in OLH to get the exact results you might want to achieve. The point is, you All the information needed is in the source CDS until you clear it (by calling ApplyUpdates()-after that, if successful, the change log is empty).

If you look at the line in CDS2, You don’t know how to tell if a particular field contains a changed value, and how to distinguish one that is only empty. A long time ago, Istr had a very good post in a Borland NTTP newsgroup in his Mark Terdington, I Think, explain how to do this. Basically, this is a question of evaluating VarIsClear on the NewValue property of the 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 CDS as XML, you can use XML operations, for example, use A DOM parser, such as the built-in Windows (see MSXML.Pas), can easily accomplish many troublesome things using the TDataSet example.

Leave a Comment

Your email address will not be published.