Page 1 of 1

Small issue with pgscript component

Posted: Fri 09 Jan 2009 21:02
by snorkel
Hi,
I have been using the script component as a work around for the inability of the query component to execute multiple commands and for the most part it works ok, except when a error occurs.
In most of my situations I have my own exception handler, for example

try
myscript.sql.add('some sql');
myscript.sql.add('some sql');
myscript.sql.add('somesql');
excute; //does not allow script exceptions to bubble up
modalresult:=mrok;

except
on e:exception do
showmessage(e.message);
end;

Because the script handles the errors it always executes the modalresult line, I tried using the scripts on error handler but it does not work the way I need it to.
The error handler would be ok if it had a option to abort and re raise the exception so the outside error handler picks up the exception.

I tried to re raise the exception that is passed in the even and then do a
eaAbort, but that does not work because the passed exeption goes out of scope and I get a invalid pointer error.

Please advise,


Snorkel

Posted: Tue 13 Jan 2009 09:08
by Plash
Use the following handler for the OnError event:

Code: Select all

procedure TForm1.PgScript1Error(Sender: TObject; E: Exception;
  SQL: String; var Action: TErrorAction);
begin
  Action := eaFail;
end;
In this case the script raises the exception, and you can catch it.

Posted: Tue 13 Jan 2009 16:08
by snorkel
Plash wrote:Use the following handler for the OnError event:

Code: Select all

procedure TForm1.PgScript1Error(Sender: TObject; E: Exception;
  SQL: String; var Action: TErrorAction);
begin
  Action := eaFail;
end;
In this case the script raises the exception, and you can catch it.
hmm, I tried that in the build I have and it didn't seem to re raise the exception so it was caught in the external try except.

Posted: Wed 14 Jan 2009 08:13
by Plash
This code works in my test.

Posted: Wed 14 Jan 2009 16:50
by snorkel
Plash wrote:This code works in my test.
Ok, I will try it again.