ApplicationEvent  Handler - On Exception

Dave_B_C
Dave_B_C used Ask the Experts™
on
I have just started using this and have worked out it doesn't run within the compiler environment but does when the program runs native? However, if I do get an error, like a duplicate insert, the next time I post a valid insert it still gives the previous error message. Do you have to reset it after each error? If so, how? If not what am I doing wrong?!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2004

Commented:
hmm,

i would use the onPostError-event
of the dataset to handle such exceptions

but, can you show, what you have done?

Commented:
Try this:

Your main forms OnCreate event do this

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnException := AppException;
end;

And AppException is:

procedure TForm1.AppException(Sender: TObject;
  E: Exception);
begin
//  handle it here...
end;

Hope that works.

Author

Commented:
Kretzschmar,
            I tried this and got the same problem... sounds like it could be a logic error, it's a pretty complex prog so I may well have missed something... will start tracing and displaying keys..!

Dumani, I'll try yours if I get stuck!

Cheers,

Dave
 
 


 
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Top Expert 2004

Commented:
btw. if you running your app within the ide,
then it may be that the exception comes twice
->first handled by the ide->then handled by your app

if so, then test it outside the ide->run the exefile directly

Author

Commented:
I have displayed keys and traced the program flow, and what is happening is that once a duplicate insert error is hit, then no activity on the table is allowed, all subsequent activity produces the same duplicate insert message? It does this even when using a DBGrid just to go to the last record, or read the next record. It is as though the table is totally locked, (although the error message is strange?) Can this happen with Delphi and Access? If so how do you free up the table after the error..? The following is the relevant update code, with diagnostic shows.. Date, Time, and Event1 are the key fields..

   For Count:= 1 to 6 do begin;
        with ADOTable1 do begin
           showmessage(SaveDate +' '+ Savetime);
           Insert;
           showmessage('2');
           FieldByName('Date').value :=  SaveDate;
           FieldByName('Time').value :=  SaveTime;
           FieldByName('Event1').value := Data1;
           FieldByName('Data2').value := Data2;
           showmessage('3');
           Post;
         end;
    end;

The following is the error handler for the OnPostError condition..

procedure TForm3.ADOTable1PostError(DataSet: TDataSet; E: EDatabaseError;
  var Action: TDataAction);
begin
   Showmessage('Error Processing RaceForm table '+ E.ClassName +' '+ E.message);
   Action := daAbort;
end;

Dave

Author

Commented:
It looks like what is happening is that after the failed Post, the record inserted is still 'available' and any other action assumes a Post is required and then fails with the duplicate error... How do you get round this? Can you rollback an insert?

Dave

Author

Commented:
A delete of the current record in the error handling routine seems to have sorted it...

Commented:
Dear expert(s),

A request has been made to close this Q in CS:
http://www.experts-exchange.com/Community_Support/CleanUp/Q_20440303.html

Without a response in 72 hrs, a moderator will finalize this question by:

 - Saving this Q as a PAQ and refunding the points to the questionner

When you agree or disagree, please add a comment here.

Thank you.

modulo

Community Support Moderator
Experts Exchange
Commented:
Saving this Q as a PAQ and refunding the points to the questionner

modulo

Community Support Moderator
Experts Exchange

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial