From Xojo Documentation
|You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!|
A Timer is an object that can execute code after a specified period of time or at a repeated interval. If added to a window via the Window Editor, it is not visible in the built application since it is not a control.
|Action||The Action event handler contains the code that will execute after the specified Period and in the specified Mode.|
|Boolean||Enables you to turn the Timer on or off.|
|Integer||The number of the control when it is part of a control array.|
|Integer||The left side of the control in local coordinates (relative to the window).|
|Mode||Integer||The interval at which the Action event will be executed.
The following class constants are available: ModeOff (0) - Off, ModeSingle (1) - Single, ModeMultiple (2) - Multiple For example: timer1.Mode=Timer.ModeSingle The default is 2, Multiple.
|Period||Integer||The time (in milliseconds) between executions.
Periods of less than or equal to zero default to a value of 1 millisecond. The default value is 1000. The rate that a Timer can actually fire depends on the speed of the host computer, the operating system, and other tasks the computer is doing. It is possible to set Period to a value that cannot be achieved by the computer that is running the application.
|Integer||The top of the control in local coordinates (relative to the window).|
|Resets the Timer and restarts it.|
The following class constants can be used to set the mode the Timer is using.
|ModeOff||The timer is off.|
|ModeSingle||The timer will fire once.|
|ModeMultiple||The timer will fire repeatedly (the default).|
Although the Timer appears in the list of Built-in controls in the Window Editor, this is done only as a convenience to programmers. In terms of the object hierarchy, the Timer is not a control. It is subclassed from Object. This means you can create Timers in your code via the New operator, just as with other objects.
The Mode property controls the interval used to execute the Timer's Action event handler. If the Mode is not 0 (ModeOff), the Timer waits for the Period to pass before executing the Action event handler. If the Mode is set to ModeOff at Runtime, the Timer will immediately cease waiting and the Action event handler will no longer be executed.
The Timer will continue to execute its Action event handler (assuming the Mode property is not set to ModeOff) regardless of whether the window is frontmost or not. The visibility of the window also has no impact on the execution of a Timer's Action event handler. The Timer has been designed so that it yields time to other applications running on the computer so as not to bog down the machine.
A Timer can be used to monitor keydown events. The following code in the Action event of a Timer detects whether the Up, Down, Left, or Right arrow keys are pressed.
StaticText1.text="left arrow key"
StaticText1.text="right arrow key"
StaticText1.text="down arrow key"
StaticText1.text="Up arrow key"