How to check for changes in a Clientdataset

Asked

Viewed 2,460 times

1

Use Delphi XE7, I need to check if you had insertion/editing in ClientDataSet before closing a certain screen, but I may close the screen and it is no longer in the insertion/editing state and still had some change in Dataset, so I need something to indicate that you had these changes, if any insertion/editing shows a message.

I know it has the function:

if MyClientDataSet.Modified then
 mensagem

but it doesn’t work, I can control every time he gives an Append/Edit in a variable, but I was wondering if the component itself already has a function that checks.

4 answers

2

You can test the state:

if cds.state id dsEditModes then ...

or if changes are pending (without applyupdate):

if cds.ChangeCount > 0 then ...

To test at the close of the form, the ideal is to use the event OnCloseQuery which has a parameter where closing can be prevented.

2


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

There is a variable of the component itself TClientDataSet calling for Logchanges a Boleana variable that comes as True by default. With this the TClientDataSet starts feeding the entire variable Changecount, showing how many records have changed.

So I can solve my doubt.

1

You can wear something like that:

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, simply remove dsInsert.

  • But when I close the screen and it’s not in the Insert/Edit state and it’s still changed, it’ll pass.

  • No, because it goes into edit state automatically after some data has been changed.

  • I managed to solve Fabio, what I needed is to know if the Tclientdataset has changed, I did not want to know what state he was in.

1

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.