Re: Event handlers...
- From: Rob Kennedy <me3@xxxxxxxxxxx>
- Date: Fri, 27 Jan 2006 11:01:59 -0600
swansnow wrote:
and it is this classname prefix which is missing from your code and so upsetting the compiler.... So method code _must_ know which instance is calling it.
Does this mean, then, that an event handler has a "self" variable?
Exactly.
What if the event handler is a class procedure of a different class, when I call it, what is in the "self" variable?
It's the same as it would have been if you'd called the class procedure directly. An event handler is little more than a delayed call.
Within a class method, "Self" refers to the class itself rather than an instance of the class.
class procedure TSwan.Snow; begin Assert(Self = TSwan); Assert(Self.InheritsFrom(TSwan)); end;
The second Assert will always pass. The first will pass when the method is called on TSwan, but not when it's called on a descendant class of TSwan.
(Is it even possible to have the event handler be a class procedure?)
Yes, it's possible. In your case, it's probably exactly what you need since you said you don't have any objects. you'll have to define a class, but you'll never have to instantiate it.
How would I set up a class to use an event handler defined in a different class?
There's really nothing special about it at all. An event handler never cares which class a method was declared it. The event handler merely needs to know which class that is. As long as you provide *something*, it can be anything you want.
I have some kinds of events which I want handled in the same way across multiple forms, like validating keypresses...
-- Rob .
- References:
- Event handlers...
- From: swansnow
- Re: Event handlers...
- From: Rob Kennedy
- Re: Event handlers...
- From: alanglloyd@xxxxxxx
- Re: Event handlers...
- From: swansnow
- Event handlers...
- Prev by Date: Re: DBGrid1.OnDrawColumnCell goes into infinite loop
- Next by Date: Re: Event handlers...
- Previous by thread: Re: Event handlers...
- Next by thread: Re: Event handlers...
- Index(es):
Relevant Pages
|