Progress
AppBuilder
Developer’s Guide
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, follow these steps:
- Click on the OCX Timer tool icon in the Objects Palette:
![]()
- 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.
- Change the Object identifier, shown in AppBuilder’s main window, to one that more clearly identifies the role of this Timer in your application.
- Choose Window
OCX Property Editor to open the Timer’s own property sheet.
- 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.
- Open the Section Editor. Set the Section to Triggers, if necessary, and choose the New button to create a new event handler. Select OCX.Tick as the event, and choose OK. AppBuilder will create a stub event handler.
- Insert the code to perform the task for which you set the timer.
This is a toy handler for the Tick event:
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.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |