TTimer

Source: source/classes/timer.prg

Standalone class

TTimer wraps the Win32 SetTimer/KillTimer API to fire a Harbour code block at configurable intervals. Timers are used for periodic background tasks, animations, auto-save, and polling.

Key DATA Members

DATATypeDescription
nIntervalNumericTimer interval in milliseconds (default 18)
bActionBlockCode block executed on each timer tick
lActiveLogicalWhether the timer is currently running
nIdNumericUnique timer identifier

Methods

MethodDescription
New( nInterval, bAction, oWnd )Create a timer. Default interval 18 ms. If oWnd is omitted, the active window is used.
Activate()Start the timer by calling SetTimer()
DeActivate()Stop the timer by calling KillTimer()
End()Deactivate and remove the timer from the global list

Commands

DEFINE TIMER oTmr INTERVAL nMs ACTION bAction OF oWnd

Example: One-Second Timer

#include "FiveWin.ch"

function Main()
   local oWnd, oTimer, nSec := 0
   DEFINE WINDOW oWnd TITLE "TTimer Demo" SIZE 300, 200
   @ 20, 20 SAY "Elapsed: " + Str( nSec ) + " seconds"
   DEFINE TIMER oTimer INTERVAL 1000 ;
      ACTION ( nSec++, oWnd:Refresh() ) ;
      OF oWnd
   oTimer:Activate()
   ACTIVATE WINDOW oWnd CENTERED
return nil

Notes

See Also