I have a TClientDataset with n fields and I have to loop through them to count how many have changed but doing:
if (Cds.fields1.Value <> Cds.fields1.OldValue) and (Cds.fields2.Value <> Cds.fields2.OldValue) etc....
or looping through Cds.fields[I] is not very 'clean'
Is there a Cds.RowChanged method or something?
You can use the TClientDataSet's
UpdateStatus
property for this:Other possible values are
usUnmodified
,usInserted
andusDeleted
. Unlike theTDataSet.Modified
property, theUpdateStatus
for the current row persists after its change(s) have been posted back to the CDS by CDS.Post. Obviously, it's up to you which of these number values you need for your application.As noted in the Online Help, you can use the
UpdateStatus
to set the value of a calculated field:You can also use its
StatusFilter
property to temporarily filter a TClientDataSet to select rows with a specficUpdateStatus
:Note that
CDS.RecordCount
with theStatusFilter
set tousModified
does not necessarily return the same value as theCDS.ChangeCount
property, because theChangeCount
value includes the number of rows inserted as well as the number that have been modified.You don't have to loop through the dataset, you can use the ChangeCount property.