Page 1 of 1

How to cancel an insert using TMyTable

Posted: Fri 28 Oct 2005 14:53
by Hans
Hi,
Before I insert a new record I want to verify if the record already exists. My approach is that I catch the BeforePost event, query the table and if record already exists just CANCEL the insert using TMyTable.Cancel.

However, after calling cancel the insert is not stopped but executed. Is it possible to abort the post? Or cannot I use the events for this purpose and should I validate the database before a Post is executed?

(The nice thing of using the BeforePost Event is, that I validate on one location.)

best regards,
hans

Posted: Fri 28 Oct 2005 16:14
by GEswin
Just call

Code: Select all

Abort;

Posted: Mon 31 Oct 2005 15:10
by Ikar
GEswin is absolutely right. Moreover, you can crash your application by calling Cancel in OnBeforePost event handler.

Posted: Mon 31 Oct 2005 18:38
by Hans
Yes, works fine. Thanks!!

best regards,
Hans