program TimerEvent_Object; // tutorial on http://www.softwareschule.ch/download/maxbox_starter2.pdf // timerevent with time dialog synchronisation or event triggering, loc's=32 // when messagebox is to early (line 25) the break condition never arrives const MILLISECONDS = 1000; //one second var myTimer: TTimer; //is an object of class TTimer! glob_count: byte; procedure timer1Event(Sender: TObject); begin incb(glob_count) //ShowMessage('this '+intToStr(glob_count)+' time') //never get if glob_count >= 5 then begin myTimer.enabled:= false; myTimer.Free; end; ShowMessage('this is from timer event '+intToStr(glob_count)+' time: ' +timeToStr(time)) end; //main program begin glob_count:= 0; ShowMessage('Press OK to start with timer at: ' +dateToStr(date)+': '+timeToStr(time)) myTimer:= TTimer.Create(self); myTimer.onTimer:= @timer1Event; myTimer.interval:= MILLISECONDS; end. {//Purpose Use the Timer component to trigger an event, either one time or repeatedly, after a measured interval. Write the code that you want to occur at the specified time inside the timer component's OnTimer event. //Tasks To specify the amount of elapsed time before the timer event is triggered, use the Interval property. To discontinue a timed event, set the timer component's Enabled property to False. TTimer encapsulates the Windows API timer functions. Unit ExtCtrls //Description TTimer is used to simplify calling the Windows API timer functions SetTimer and KillTimer, and to simplify processing the WM_TIMER messages. Use one timer component for each timer in the application. The execution of the timer occurs through its OnTimer event. TTimer has an Interval property that determines how often the timer’s OnTimer event occurs. Interval corresponds to the parameter for the Windows API SetTimer function. Caution: Limitations on the total number of timers system-wide are system dependent. //Sender of a button click: The parameter "Sender" references the control that was used to call the method. If you click on the Button1 control, causing the Button1Click method to be called, a reference or pointer to the Button1 object is passed to Button1Click in the parameter called Sender.}