skip to main content
OpenEdge Development: AppBuilder
Other Objects : Timer objects (ActiveX)
 
Timer objects (ActiveX)
The majority of GUI‑based applications follow an asynchronous, event‑driven model similar to that for real‑time or process‑control applications. The majority of their time is spent waiting for input, in this case from the user rather than some hardware device.
But there are a number of cases for which it can be convenient to perform some activity at a regular interval, regardless of what the user might be doing. Providing a real‑time clock display is perhaps the simplest case. Checking or reporting on the state of some lengthy process is another.
AppBuilder supplies a simple OCX Timer object for your use. The timer is interrupt‑driven from the system clock, and generates a single event (Tick) at some regular interval you determine. You configure the Interval property to be a multiple of 1/1000 of a second, and write an event handler to react to the Tick event. The timer will continue to generate this event with metronomic regularity until you reset or disable it.
Caution: It takes a certain amount of time to react to any event. If you set up a situation where you must respond to every Tick event, but you configure them to occur more frequently than you can handle them, your application might behave in a way that is both strange and hard to debug.
To create and configure a Timer instance:
1. Click PSTimer in the Objects Palette.
2. Move your cursor to some bare spot in your workspace and click to place the object. The Timer object has a design‑time representation, but is invisible at run time.
3. Change the Object identifier, shown in AppBuilder’s main window, to one that more clearly identifies the role of this timer in your application.
4. Choose WindowOCX Property Editor to open the timer’s own property sheet.
5. Set the Interval property to the desired integer frequency, representing thousandths of a second. For example, to get a Tick event every second, set Interval to 1000. For 1/10th of a second, set Interval to 100, and for a tick every 5 seconds, set Interval to 5000. Close the window.
6. Open the Section Editor. Set the Section to Triggers, if necessary, and click New to create a new event handler. Select OCX.Tick as the event, and click OK. AppBuilder will create a stub event handler.
7. Insert the code to perform the task for which you set the timer.
This is a toy handler for the Tick event:
 
/*
** In the definitions section:
*/

DEFINE VARIABLE bTickTock AS LOGICAL INITIAL FALSE.

/*
** In the OCX.Tick event handler:
*/

bTickTock = NOT( bTickTock ). /* flip the value */
IF bTickTock THEN /* decide whether to tick or tock */
MESSAGE "Tick".
ELSE
MESSAGE "Tock".
When run, this toy event handler will alternately, and endlessly, write “Tick” or “Tock” to the message area of the window, presuming you have configured your window object to have a message area. The endless, synchronous looping action comes not from any loop code in the handler, but rather from the fact that the Timer itself is bound to the endlessly‑operating system clock.