StatusFilter on ClientDataSet
I'm having some difficulties using ClientDataSet.StatusFilter := [usDeleted]
.
On the other hand. If I use ClientDataSet.CreateDataSet
which isn't hooked up to a provider and only use the ClientDataSet as an in-memory DataSet then the StatusFilter works as described in the documentation.
The only way I can get my first ClientDataSet that is hooked up to a provider to display the deleted records is by using the ClientDataSet.Delta property. But this doesn't allow me to Revert a deleted record.
//Note: cds.LogChanges = true
cds := TClientDataSet.Create(nil);
cds.Da开发者_JAVA百科ta := MyClientDataSet.Delta;
cds.First;
while not cds.eof do
begin
case cds.UpdateStatus of
usModified:
begin
ShowMessage('Modified');
cds.RevertRecord;
end;
usInserted: ShowMessage('Inserted');
usDeleted: ShowMessage('Deleted');
end;
cds.Next;
end;
cds.Free;
What am I doing wrong?
The code you describe
ClientDataSet1.StatusFilter := [usDeleted];
is the correct way to include in your current ClientDataSet view only those records that have been deleted. I do not understand why it is not working for you, as I use this approach in my code all the time and it has never failed. The only thing I can think of is that you may have called ApplyUpdates or CancelUpdates prior to setting the StatusFilter property, or you may have LogChanges set to False (it's default is True).
By the way, to cancel status filter set it to an empty set, like this:
ClientDataSet1.StatusFilter := [];
That will include inserted, modified, and unmodified records in your view. The deleted records will not appear in the current view.
精彩评论