Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 14 in printed book and digital formats -- plus a one-year subscription so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 12.1 ('Smart Localization')
Instant purchase and download via GumRoad!

COLUMN

Using AddHandler

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?

AddHandler and RemoveHandler give you a way to do just that.

Using a Timer

Let look at an example: say that you have a Calendar control that's a subclass of the Canvas. Your calendar has an AddEvent method 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 Refresh when 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 Refresh.

One place where this is handy is for handling Timer events. Normally you can just place a timer on your window and add code to the Action event 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 Timer subclass that knows about the class that you want to use it in. So, for example, if you have a Calendar class, then you might create CalendarUpdateTimer where you store a reference to the calendar that you want to update.

...End of Excerpt. Please purchase the magazine to read the full article.