Timer class

The fpTimer unit implements a timer class which can be used on all supported platforms. The timer class uses a driver class which does the actual work.

A default timer driver class is implemented on all platforms. It will work in GUI and non-gui applications, but only in the application's main thread.

An alternative driver class can be used by setting the variable to the class pointer of the driver class. The driver class should descend from .

Abstract driver class

TFPTimerDriver is the abstract timer driver class: it simply provides an interface for the class to use.

The fpTimer unit implements a descendent of this class which implements the default timer mechanism.

Custom timer class

TFPCustomTimer is the timer class containing the timer's implementation. It relies on an extra driver instance (of type ) to do the actual work.

TFPCustomTimer publishes no events or properties, so it is unsuitable for handling in an IDE. The descendent class publishes all needed events of TFPCustomTimer.

Create a new timer Create instantiates a new TFPCustomTimer instance. It creates the timer driver instance from the DefaultTimerDriverClass class pointer. Owner of the timer instance Release a timer instance from memory Destroy releases the timer driver component from memory, and then calls Inherited to clean the TFPCustomTimer instance from memory. Start the timer

StartTimer starts the timer. After a call to StartTimer, the timer will start producing timer ticks.

The timer stops producing ticks only when the StopTimer event is called.

StopTimer Enabled OnTimer
Stop the timer

Stoptimer stops a started timer. After a call to StopTimer, the timer no longer produces timer ticks.

StartTimer Enabled OnTimer
Timer class with published properties

TFPTimer implements no new events or properties, but merely publishes events and properties already implemented in : Enabled, OnTimer and Interval.

The TFPTimer class is suitable for use in an IDE.

Enabled OnTimer Interval
Start or stop the timer Enabled controls whether the timer is active. Setting Enabled to True will start the timer (calling StartTimer), setting it to False will stop the timer (calling StopTimer). StartTimer StopTimer OnTimer Interval Timer tick interval in milliseconds.

Interval specifies the timer interval in milliseconds. Every Interval milliseconds, the OnTimer event handler will be called.

Note that the milliseconds interval is a minimum interval. Under high system load, the timer tick may arrive later.

OnTimer Enabled
Event called on each timer tick. OnTimer is called on each timer tick. The event handler must be assigned to a method that will do the actual work that should occur when the timer fires. Interval Enabled Create new driver instance Create should be overridden by descendents of TFPTimerDriver to do additional initialization of the timer driver. Create just stores (in Timer) a reference to the ATimer instance which created the driver instance. Timer Timer instance that created the driver Start the timer StartTimer is called by . It should be overridden by descendents of TFPTimerDriver to actually start the timer. Stop the timer StopTimer is called by . It should be overridden by descendents of TFPTimerDriver to actually stop the timer. Timer tick Timer calls the timer event. Descendents of TFPTimerDriver should call Timer whenever a timer tick occurs. Class of TFPTimerDriver TFPTimerDriverClass is the class pointer of it exists mainly for the purpose of being able to set , so a custom timer driver can be used for the timer instances. Actual timer class to be used

DefaultTimerDriverClass contains the class pointer that should be used when a new instance of is created. It is by default set to the system timer class.

Setting this class pointer to another descendent of TFPTimerDriver allows to customize the default timer implementation used in the entire application.