Board index » delphi » OnPostError event

OnPostError event

I am trying to trap errors when posting to a database but I am not
having much luck.  I am using delphi 3 and it's own local database
support.  I am trying to make a fault tolerant system, so when a user
posts a record to the database instead of crashing the program I would
like to warn them and get them to make corrections.  It seems that the
OnPostError for TTables would be the likely place to do this but I can't
seem to make it work and apparently niether can borland.

What I mean by this this that Delphi 3 ships with a demo program for
trapping database errors. In c:\program files\borland\delphi
3.0\demos\db\dberrors, run this project.  When you make an error happen
it
doesn't manage to trap errors any better then my code.  Could someone
please help make ONPostError event work.  I know it's possible to do
what
Steve says to here:

Quote
Steve Fischkoff (TeamB) wrote:

> I've had good luck with structured exceptions. That is:

>         try
>                 Table1.Post;
>         except
>                 on EDatabaseError do begin .... end;
>         end;

> You can put whatever recovery code is relevant in the begin....end
> above.

> Steve F (Team B)

But this would mean though that I would have to put this code into any
place
that posted to one of my tables.  If I could get the OnPostError event
working then I would just have to handle the exception in one place.  If
I am missing the point please let me know.  Thanks for your help
 

Re:OnPostError event


Quote
Ivan I. Sears wrote:

> I am trying to trap errors when posting to a database but I am not
> having much luck.  I am using delphi 3 and it's own local database
> support.  I am trying to make a fault tolerant system, so when a user
> posts a record to the database instead of crashing the program I would
> like to warn them and get them to make corrections.  It seems that the
> OnPostError for TTables would be the likely place to do this but I can't
> seem to make it work and apparently niether can borland.

> What I mean by this this that Delphi 3 ships with a demo program for
> trapping database errors. In c:\program files\borland\delphi
> 3.0\demos\db\dberrors, run this project.  When you make an error happen
> it
> doesn't manage to trap errors any better then my code.  Could someone
> please help make ONPostError event work.  I know it's possible to do
> what
> Steve says to here:

> Steve Fischkoff (TeamB) wrote:

> > I've had good luck with structured exceptions. That is:

> >         try
> >                 Table1.Post;
> >         except
> >                 on EDatabaseError do begin .... end;
> >         end;

> > You can put whatever recovery code is relevant in the begin....end
> > above.

> > Steve F (Team B)

> But this would mean though that I would have to put this code into any
> place
> that posted to one of my tables.  If I could get the OnPostError event
> working then I would just have to handle the exception in one place.  If
> I am missing the point please let me know.  Thanks for your help

I just wrap a try..except around the Post:

try
  Sku.Post;
except on EDBEngineError do
begin
  Sku.Cancel;
  ShowMessage('You can''t do that!');
end;
end;

Re:OnPostError event


On Wed, 04 Feb 1998 12:01:40 -0400, "Ivan I. Sears" <ise...@unb.ca>
wrote:

Quote
>What I mean by this this that Delphi 3 ships with a demo program for
>trapping database errors. In c:\program files\borland\delphi
>3.0\demos\db\dberrors, run this project.  When you make an error happen

Make sure you try it with "Break On Exceptions" turned off in the
Delphi IDE.  That might be the cause of the problems.  It's under
Tools | Environment.  This setting only effects exceptions when you
are running the app from inside Delphi.

If that's not the problem, email me.  I've got some sample code I
presented to the local Delphi users group, that shows db exception
handling.

Chuck Gadd
Director of Software Development, {*word*104} FX Communications.
e-mail:cgadd...@SPAM-cfxc.com  http://www.csd.net/~cgadd
Remove the -NO SPAM- from my email address to send me e-mail.
*** I boycott businesses that send me unsolicited email adverti{*word*224}ts ***

Re:OnPostError event


Quote
>But this would mean though that I would have to put this code into any
>place
>that posted to one of my tables.  If I could get the OnPostError event
>working then I would just have to handle the exception in one place.  If
>I am missing the point please let me know.  Thanks for your help

The Post has already happened before you get to this event and it has
failed.  All the OnPostError event does is give you the EDatabaseError
from a post and allow you 3 options.

1       Aborts the post operation and displays an error message.
2       Aborts the post operation without displaying a message.
3       Take some corrective action in the event and repost

So you can examine the error code and pick one of these options.

--
Brian Bushay (TeamB)
Bbus...@DataGuidance.com

Re:OnPostError event


On Thu, 05 Feb 1998 06:14:23 GMT, BBus...@DataGuidance.com (Brian

Quote
Bushay TeamB) wrote:

>>But this would mean though that I would have to put this code into any
>>place
>>that posted to one of my tables.  If I could get the OnPostError event
>>working then I would just have to handle the exception in one place.  If
>>I am missing the point please let me know.  Thanks for your help

>The Post has already happened before you get to this event and it has
>failed.  All the OnPostError event does is give you the EDatabaseError
>from a post and allow you 3 options.

>1   Aborts the post operation and displays an error message.
>2   Aborts the post operation without displaying a message.
>3   Take some corrective action in the event and repost

>So you can examine the error code and pick one of these options.

I am having a similar problem where the OnPostError is not firing.  It
is on an implied post generated from within a third-party grid
control.  There are two fields in the table which are R.I. related to
a validity table.  If they are not valid, the BDE throws an exception
but apparently does not fire OnPostError.  A ShowMessage as the first
line of the event never happens.  Setting a breakpoint on that line
shows the BDE exception dialog happens elsewhere  instead of flowing
throught that block.

The post is implied by cursor movement rather than being explicit
within my code.  That means I cannot wrap it with Try/Except.

It happens in too many places to be easily handled globally through
Application.OnException.

I have tried making the two fields marked TField Required := False.
No help.

Any ideas?
Thanks!
-Bob Riddle
BobRid...@wordlnet.att.net

Re:OnPostError event


Quote

>The post is implied by cursor movement rather than being explicit
>within my code.  That means I cannot wrap it with Try/Except.

>It happens in too many places to be easily handled globally through
>Application.OnException.

>I have tried making the two fields marked TField Required := False.
>No help.

>Any ideas?

Does this only happen when the post is within the 3rd party gid
contorol?  If so have you tried asking the Grid component company?

--
Brian Bushay (TeamB)
Bbus...@DataGuidance.com

Other Threads