Board index » delphi » How to translate 'Sender'

How to translate 'Sender'

I am using the following code to log exceptions in my app. Is it
possible to identify further where the exception originates?
Possibly translating 'Sender' somehow?

procedure TfmCoreStart.ApplicationEvents1Exception(Sender:
TObject;
  E: Exception);
var FileName:string;
logfile:textfile;
begin
FileName:=ChangeFileExt(Application.Exename,'.log');
Assignfile(logfile,FileName);
if fileexists(filename) then Append(logfile)
else rewrite(logfile);

Writeln(logfile,datetimetostr(now)+':'+e.message);
{if not checkboxsilent.Checked then

Quote
}Application.showexception(e);

closefile(logfile);
end;

Pat Bell

 

Re:How to translate 'Sender'


P.S.Bell wrote in <VA.00000308.0026e...@patbell.demon.co.uk>...

Quote
> I am using the following code to log exceptions in my app. Is it
> possible to identify further where the exception originates?
> Possibly translating 'Sender' somehow?
> procedure TfmCoreStart.ApplicationEvents1Exception(Sender:
> TObject;
>   E: Exception);

You can find out the class name of the sender (ClassName method). You can
check if sender is equal to one of the components on one of your forms.
If you're sure Sender is a component, you can cast it to TComponent and
use its name. Etc., etc. Use your imagination.
--
Rudy Velthuis (TeamB)                http://delphi-jedi.org

Re:How to translate 'Sender'


Quote
> I am using the following code to log exceptions in my app. Is it
> possible to identify further where the exception originates?
> Possibly translating 'Sender' somehow?

Do you mean like java that has a call stack (in reverse order though, I
can't remmeber, but it looked funny :) attached to event instances?

Regards,
Thomas

Re:How to translate 'Sender'


Quote
In article <94n4bt$ac...@bornews.inprise.com>, Rudy Velthuis (TeamB) wrote:
> P.S.Bell wrote in <VA.00000308.0026e...@patbell.demon.co.uk>...

> > I am using the following code to log exceptions in my app. Is it
> > possible to identify further where the exception originates?
> > Possibly translating 'Sender' somehow?

> > procedure TfmCoreStart.ApplicationEvents1Exception(Sender:
> > TObject;
> >   E: Exception);

> You can find out the class name of the sender (ClassName method). You can
> check if sender is equal to one of the components on one of your forms.
> If you're sure Sender is a component, you can cast it to TComponent and
> use its name. Etc., etc. Use your imagination.

Since this is a general application.onexception I guess it might not be a
component generating the exception. So can I first check if it is a
Tcomponent?

I guess I could do something like:

Try
with sender as TComponent do sTemp:=TComponent.Name+':'+E.Message;
except sTemp:=E.Message;
Writeln(logfile,datetimetostr(now)+':'+sTemp);
end;

But wouldn't that get tied up with the exception handling?

Pat Bell

Re:How to translate 'Sender'


P.S.Bell wrote in <VA.0000030a.008d9...@patbell.demon.co.uk>...

Quote
> Since this is a general application.onexception I guess it might not be a
> component generating the exception. So can I first check if it is a
> Tcomponent?

If Sender is TComponent then ...

Don't use "as" and "try". Just do an "is" test.
--
Rudy Velthuis (TeamB)                http://delphi-jedi.org

Other Threads