Re: Event handlers...



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
.



Relevant Pages

  • Re: Trouble with DeselectAll()
    ... DoCmdbehaves exactly like calling DeselectAll(), ... Calling DoCmdtwice also works. ... from an event handler seems to be what is broken. ...
    (microsoft.public.visio.developer)
  • Re: Spanning thread in WS Async Call
    ... I am calling a web service asynchronously as follows ... I want to span thread here to do some operation on the the result data and ... Why don't you do your processing within the event handler? ... John Saunders | MVP – Windows Server System – Connected System Developer ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: How to programmatically invoke Click event of the Button ?
    ... Or if I need to invoke an event of Label class? ... click event handler should call the TakeOrdermethod. ... you can call TakeOrderinstead of calling the ... was just calling your button's OnClick() method to do what the button was ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Idea
    ... its context object could be the control. ... that Sender is a requisite in every event handler, ... And I take it you mean the called code, not the calling code? ... > called in which you pass in a method pointer to set values in the ...
    (comp.lang.pascal.delphi.misc)
  • Re: Call Sub vs. fake a key press
    ... Rather then calling an event handler directly, ... > containing the code and that sub would be called from the If in the open ... > routine and from the stop routine. ...
    (microsoft.public.dotnet.languages.vb)