Unit:
AxMisc
Description:
The AxMisc unit provides the timer routines used internally by Async Professional CLX. You might find these routines handy for your programs as well. In almost all cases you will find it more convenient to use timer triggers with a TApxComPort component rather than working with the timer routines directly. If you don't want to use AxMisc timers directly then you don't need to read this section.
Async Professional CLX's basic time unit is the millisecond. There are 1000 milliseconds in one second. Keep in mind that base time unit of milliseconds doesn't mean that Async Professional CLX's timer routines can accurately time events with true millisecond resolution. The actual resolution achieved will depend on the operating system capabilities.
Unless otherwise specified, all Async Professional CLX routines that have time-out parameters—the mSecs parameter to the TApxComPort SetTimerTrigger method, for example—require a value expressed in milliseconds.
The basic timer record is called an EventTimer. When an EventTimer is initialized it is passed the duration of the event. EventTimers can also be used to measure elapsed times, in which case the initial duration isn't important and can be set to zero.
Here is an example program that uses timer functions:
uses AxMisc;
procedure TForm1.Button1Click(Sender: TObject);
var
ET : EventTimer;
begin
Aborted := False; { Global Boolean Flag }
Label2.Caption := '';
NewTimer(ET, 60*1000); { 60 seconds }
repeat
Label1.Caption := Format(
'Elapsed millisecs: %d Remaining millisecs: %d',
[ElapsedTime(ET), RemainingTime(ET)]);
Application.ProcessMessages;
until Abort or TimerExpired(ET);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Aborted := True;
Label2.Caption := 'Aborted';
end;
An EventTimer is initialized by calling NewTimer, which is passed an EventTimer and the number of milliseconds until expiration.
This program loops continuously, displaying the elapsed milliseconds and the remaining milliseconds, until the timer expires or a key is pressed.
It is perfectly legal to use the ElapsedTime routines even after a timer has expired. If the example program called ElapsedTime after the timer had expired, it would still return the number of milliseconds since the timer was started.
A timer is good for 24 hours at most. If you reference a timer after 24 hours, the results are modulo 24 hours.