From Xojo Documentation

Revision as of 21:51, 7 October 2010 by Dbrandt (talk | contribs) (added AddEvent)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

{MethodBox | name=Add Handler | platform=all | newinversion=2010r4 | scope=global }}

Used to delegate the responsibility of handling an event to a method.

The event can be any event, not just control events, and the method can be any method that is in scope.

You pass the actual events and the actual methods as the parameters.

AddHandler <event>, <method>
Part Description
event The event you want a method to handle.
method The method you wish to handle the event.


This example specifies a method called “ MyTimeOut” as the handler of the Action event of a Timer that was instantiated in code:

AddHandler t.Action, AddressOf MyTimeOut

In this way, the Action event of that class is implemented by the specified method. The statment tells the Event handler which method is handling that event.

The sender can be a super class as well. The important thing is that the handler’s signature has to match the event’'s.

For example, the following would also work for a canvas since RectControl is where MouseDown is implemented:

Foo(sender as RectControl, x as integer, y as integer) as boolean

A handler can handle any number of events, but an event can only have one event handler. To change the event handler for an event (after you have added one), you must first remove the existing handler using RemoveHandler and then add the new one. If you don’t, a RuntimeException will be raised.

See Also

RemoveHandler statement