How to check for changes to a ClientDataSet

1

I use Delphi XE7 , I need to check if I have inserted / edited in ClientDataSet before closing a particular screen, but I can close the screen and it is no longer in insert / editing and even had some change in the DataSet, so I need something that indicates that you had those changes, if there is any insert / edit show a message.

I know you have the function:

if MyClientDataSet.Modified then
 mensagem

But it does not work, I can control every time it appends an Append / Edit to a variable, but wanted to know if the component itself already has a function that checks.

    
asked by anonymous 16.03.2017 / 15:57

4 answers

2

I found what I was looking for, after some research, I'll explain how to use it.

There is a variable of the TClientDataSet itself called LogChanges a variable Boolean that comes as True by default. As a result, TClientDataSet starts feeding the entire ChangeCount variable, showing how many records have changed.

So I can resolve my question.

    
16.03.2017 / 17:56
2

You can test state :

if cds.state id dsEditModes then ...

or, if pending changes (without applyupdate ):

if cds.ChangeCount > 0 then ...

To test on form closure, the ideal is to use the OnCloseQuery event that has a parameter where you can prevent closing.

    
17.03.2017 / 12:36
1

You can use something like this:

if (meucds.state in [dsEdit, dsInsert]) then
begin
   // seu código aqui...
end;

In this example it also considers whether it is in insert state, if you just want to check if it is in edit state, just remove dsInsert.

    
16.03.2017 / 15:59
0

A more complete solution would be to use ClientDataSet.UpdateStatus . For each record, it informs whether it has been entered ( usInserted ), edited ( usModified ) or deleted ( usDeleted , but to see it, you need to change StatusFilter / p>

This information is available for when ClientDataSet is caching data ( ClientDataSet ) and especially LogChanges is only correctly set when usModified is in DataSet mode (because there is no way to know if the record has been edited until a post is given.)

    
16.06.2017 / 00:21