How to cancel an insert using TMyTable

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Hans
Posts: 52
Joined: Wed 24 Aug 2005 20:05

How to cancel an insert using TMyTable

Post by Hans » Fri 28 Oct 2005 14:53

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

GEswin
Posts: 186
Joined: Wed 03 Nov 2004 16:57
Location: Spain
Contact:

Post by GEswin » Fri 28 Oct 2005 16:14

Just call

Code: Select all

Abort;

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Mon 31 Oct 2005 15:10

GEswin is absolutely right. Moreover, you can crash your application by calling Cancel in OnBeforePost event handler.

Hans
Posts: 52
Joined: Wed 24 Aug 2005 20:05

Post by Hans » Mon 31 Oct 2005 18:38

Yes, works fine. Thanks!!

best regards,
Hans

Post Reply