Xojo has a way to connect events to handlers outside of a Window or sublcass.
Issue: 12.1 (January/February 2014)
Author: Seth Verrinder
Author Bio: Seth is a consultant who uses Real Studio every day in his job at BKeeney Software, Inc.
Article Description: No description available.
Article Length (in bytes): 5,235
Starting Page Number: 70
Article Number: 12108
Related Link(s): None
Excerpt of article text...
Usually you handle events in Xojo by adding code to the window that contains the control. Xojo automatically calls your code when the event is raised. This only works for objects that are placed on a window, though. What if you want to handle an event raised by an object that's not placed on a window?
RemoveHandlergive you a way to do just that.
Using a Timer
Let look at an example: say that you have a
Calendarcontrol that's a subclass of the
Canvas. Your calendar has an
AddEventmethod that adds an event to your calendar and you want to automatically refresh the display when that happens. But someone might add a bunch of events and you don't want to repaint the canvas for each one. You could leave it up to the calling code to call
Refreshwhen it's done. Or, you could add a method that takes a list of events. Another approach is to start a timer inside of
AddEvent. When the timer fires, it calls
One place where this is handy is for handling
Timerevents. Normally you can just place a timer on your window and add code to the
Actionevent in the window. But, if you want to use a Timer that's not on a window, then you can't do that. There are a few options here:
- You can create a separate
Timersubclass that knows about the class that you want to use it in. So, for example, if you have a
Calendarclass, then you might create
CalendarUpdateTimerwhere you store a reference to the calendar that you want to update.
...End of Excerpt. Please purchase the magazine to read the full article.