In the AfterPost event handler for a ClientDataSet, I need the information if the ApplyUpdates function for the current record will do an update or an insert. The AfterPost event will be executed for new and updated records, and I do not want to declare a new Flag variable to indicate if a 'update' or ' insert' operation is in progress. Example code:
The application will write a log in the AfterPost method, after ApplyUpdate has completed. So this method is the place which is closest to the action, I would prefer a solution which completely can be inserted in this event handler. How could I implement the IsInserting function, using information in the ClientDataSet instance QryTest? Edit: I will try ClientDataSet.UpdateStatus which is explained here. | |||||||||||||
|
ApplyUpdates doesn't give you that information - since it can be Inserting, updating and deleting. ApplyUpdates apply the change information stored on Delta array. That change information can, for example, contain any number of changes of different types (insertions, deletions and updatings) and all these will be applied on the same call. On TDatasetProvider you have the BeforeUpdateRecord event (or something like that, sleep does funny things on memory :-) ). That event is called before each record of Delta is applied to the underlying database/dataset and therefore the place to get such information... But Showmessage will stop the apply process. EDIT: Now I remembered there's another option: you can assign Delta to another clientdataset Data property and read the dataset UpdateStatus for that record. Of course, you need to do this before doing applyupdates... | |||||||||||||||||
|
Did you find this question interesting? Try our newsletter
Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).
BeforeUpdateRecord event on TDataSetProvider is defined as:
Parameter
Note: this event signature is from Delphi 7. I don't know if it changed in later versions of Delphi. | |||
Set the ClientDataSet.StatusFilter to an TUpdateStatus value, and then read ClientDataSet.RecordCount for example,
will return the number of Delete queries that will be executed. Note two things, however. Setting StatusFilter to usModified always includes both the modified and unmodified records, so you take half of that value (a value of 4 means 2 Update queries will be executed). Also, setting StatusFilter to [] (an empty set) is how you restore to default view (Modified, Unmodified, and Inserted) Make sure that any unposted changes have been posted before doing this, otherwise unposted changes may not be considered. | |||||
|