I'm using Dephi 10.1 Berlin and Access 2013.
My problem is related to TADODataSet.Cancel()
.
I want to show my user a message box asking for a confirmation before posting, in case data has been modified.
In the TADODataSet.BeforePost
event, I added the following code:
if Application.MessageBox('Save changes?', '', 52) = idNo then
ADODataSet1.Cancel;
If the user click on btnNo
, something unexpected happens.
Changes are canceled from the current record, but a new record with all fields empty is created.
The only field with some data is the one that was previously modified by the user.
If I cancel the modification via the cancel button of TDBNavigator
, everything is fine.
If I simulate a click of the Cancel button of the TDBNnavigator
in the BeforePost
event:
if Application.MessageBox('Save changes?', '', 52) = idNo then
DBNavigator1.BtnClick(nbCancel);
I have the same behaviour, so a new empty record is created.
Any suggestion?
The help for TADODataSet.BeforePost says in part:
So:
Note this is meant for preventing changes that don't pass validation (the common use for BeforePost) from being posted. It doesn't reset the edit buffers like cancel does. Usually that is a separate function in the UI so the user doesn't have to reenter all the changed data in the edits each time posting is rejected by calling abort in BeforePost.