0

I am in a BeforePost event handler hoping to cancel the post before it goes through. At the end of my BeforePost function I call DataSet->Cancel(); and when debugging through this I see it go from my function to the TDataSet.DoBeforePost function then to the TDataSet.Post; where it calls CheckOperation(). CheckOperation throws an exception (which I tried to avoid by calling Cancel() ) because the data is incorrectly entered and the user sees this error.

Is there something in this order of operations that I am doing wrong? Any kind of ideas or guidance would be greatly appreciated.

user912447
  • 696
  • 1
  • 11
  • 31

1 Answers1

1

If I remember correctly then you should use Abort() instead of Cancel();

Riho
  • 4,523
  • 3
  • 33
  • 48
  • Abort() throws you completely out of the call back however, and gives GUI control back to the user. All I want to do is Cancel the pending changes so that my AfterPost function can run as well. – user912447 Feb 03 '13 at 15:51
  • If you cancel all your changes then there is nothing to Post. Would AfterPost be called in this case? ASnd if user actually entered incorrect data then you should Abort and give control back to user, so he can fix his error. That's what BeforePost is for. – Riho Feb 04 '13 at 05:59
  • Unfortunately I do in fact need to call the AfterPost. My database is set up in such a (weird) way that I can't actually let the ADOQuery do the posting, it will fail every time. Therefore in the BeforePost I manually insert the information that I need and then need to cancel. But Cancel seems to have no effect whatsoever. – user912447 Feb 06 '13 at 14:37
  • I think Cancel is meant to be called when You don't want call Post or when your Post crashes and you catch the exception. I would recommend to do everything in BeforePost and then just Abort. Or just write your own methods for Posting data – Riho Feb 07 '13 at 07:13
  • There are ways around the problem sure, I'm just dumbfounded as to why Cancel() seems to do nothing. I have it working like you just suggested now (manually calling the "AfterPost" right before the Abort) but it is strange that their documentation doesn't mention this problem. – user912447 Feb 07 '13 at 13:21
  • I think that when you are already in Post() process (Post() is the one that calls the BeforePost() and AfterPost()) then Cancel just is ignored as it works on the same level as Post. – Riho Feb 08 '13 at 08:19
  • Okay, I guess Cancel() just isn't intended to be called from a BeforePost(). – user912447 Feb 08 '13 at 14:30