Board index » delphi » Calling an event handler

Calling an event handler

Hi,

In one of my procedures I would like to call the OnExit event handler
for whatever control is active on the form.  I tried something like this

var
  OnExitProc : TNotifyEvent;
begin
  OnExitProc := ActiveControl.OnExit;
  OnExitProc(self);
end;

But the compiler says that OnExit is undeclared.  What am I doing wrong
here? What is the right way to call the OnExit handler? Is it possible?

--
Will Garces
wlgar...@mail.uccs.edu

 

Re:Calling an event handler


In article <57riid$...@harpo.uccs.edu>, wlgar...@elvis.UCCS.edu says...

Quote
>Hi,
>In one of my procedures I would like to call the OnExit event handler
>for whatever control is active on the form.  I tried something like this
>var
>  OnExitProc : TNotifyEvent;
>begin
>  OnExitProc := ActiveControl.OnExit;
>  OnExitProc(self);
>end;
>But the compiler says that OnExit is undeclared.  What am I doing wrong
>here? What is the right way to call the OnExit handler? Is it possible?

You need to check whether or not it's been assigned fist:

begin
   if Assigned(ActiveControl.OnExit)
   then ActiveControl.OnExit(ActiveControl);
end;

Assigned simply checks to see if the pointer to the handler is NIL.
In general it's a good idea to pass the expected parameters to the event
handlers even though they might never use them...

Hope this helps,
Jochen

Other Threads