From Clomosy Docs

AComponent : Specifies the parent of the object to be defined.

xName : The name of the defined timer should be written.

xInterval : Type the trigger time of the time in milliseconds. If we write the time as 0 here, the trigger will not occur at all.


If there is any code or event that you want to run at certain time intervals or within a certain period of time, the component we need to do this desired job is the TClTimer component.
If there is code that needs to be executed based on time intervals, it should be written in the tbeOnTimer event of the TClTimer component. Then, by setting the Interval property of the component in milliseconds, the written code will be executed at the desired time intervals.

Feature Use of Definition
TClTimer Timer1: TclTimer; A variable belonging to the TclTimer class is created.
AddNewTimer Timer1 = Form1.AddNewTimer(Form1,'Timer1',1000); // the action is triggered every 1 second. A new TclTimer is added to the form.
Interval Timer1.Interval = 1000; When creating an object, the time interval to be triggered is specified in the third parameter of the AddNewTimer function. If we set the time to 0 here, the trigger will never occur. In this case, a trigger time can be assigned to the Interval property to enable the triggering. Thus, even if it's set to 0, the triggering will still occur with the interval.

This property specifies the intervals at which the timer component will operate. If the interval is set to 1000, the timer will run every second, meaning 1000 represents 1 second. If the interval value is 500, the timer will run twice per second.

Enabled Timer1.Enabled = True; //or False It is the property that determines whether the TClTimer component will run or not. If the Enabled property is set to true, the timer executes its code at the specified intervals. If the Enabled property is set to false, the timer does not run.
tbeOnTimer Form1.AddNewEvent(Timer1,tbeOnTimer,'timerShow'); //timerShow : Void If we want to activate the click event of our TCLTimer component, it is done using AddNewEvent. Here, tbeOnTimer is written as the second parameter. In the last parameter, the action to be triggered on click is specified.

Example
In the example, a stopwatch is created using a timer. The timer can be started and stopped with two buttons.

var
  MyForm:TclForm;
  GetTimer: TClTimer;
  GetStartTimerBtn,GetStopTimerBtn : TClProButton;
  duration, sn ,ss : Integer;
  lblTimer : TclLabel;
  lytTimer :TClLayout;
  pnlTimer :TClPanel;

void BtnStartClick;
{
  //GetTimer.Interval = 100; //You can enable it if you don't use a time trigger when calling AddNewTimer.
  GetTimer.Enabled = True;
  MyForm.AddNewEvent(GetTimer,tbeOnTimer,'timerShow');
}

void BtnStopClick;
{
  GetTimer.Enabled = False;
}

void timerShow;
{
  Inc(duration);
  sn = (duration div 10);
  ss = (duration mod 10);
  lblTimer.Caption = IntToStr(sn)+'.'+IntToStr(ss);
}

{
  duration = 0;
  MyForm = TclForm.Create(Self);
  GetTimer= MyForm.AddNewTimer(MyForm,'GetTimer',100); 
  
  pnlTimer=MyForm.AddNewPanel(MyForm,'pnlTimer');
  pnlTimer.Align=AlCenter;
  pnlTimer.Height=150;
  pnlTimer.Width=300;
  
  lytTimer = MyForm.AddNewLayout(pnlTimer,'lytTimer');
  lytTimer.Align=ALTop;
  lytTimer.Height = 70;
  lytTimer.Width = 300;
  
  GetStartTimerBtn = MyForm.AddNewProButton(lytTimer,'GetStartTimerBtn','Start');
  GetStartTimerBtn.Align = alLeft;
  GetStartTimerBtn.Width = 100;
  GetStartTimerBtn.Height = 40;
  GetStartTimerBtn.clProSettings.BorderColor = clAlphaColor.clHexToColor('#7A3E65');
  GetStartTimerBtn.clProSettings.RoundHeight = 2;
  GetStartTimerBtn.clProSettings.RoundWidth = 2;
  GetStartTimerBtn.clProSettings.BorderWidth = 3;
  GetStartTimerBtn.clProSettings.IsRound = True;
  GetStartTimerBtn.SetclProSettings(GetStartTimerBtn.clProSettings);
  MyForm.AddNewEvent(GetStartTimerBtn,tbeOnClick,'BtnStartClick');
  
  
  GetStopTimerBtn = MyForm.AddNewProButton(lytTimer,'GetStopTimerBtn','Stop');
  GetStopTimerBtn.Align = alRight;
  GetStopTimerBtn.Width = 100;
  GetStopTimerBtn.Height = 40;
  GetStopTimerBtn.SetclProSettings(GetStartTimerBtn.clProSettings);
  MyForm.AddNewEvent(GetStopTimerBtn,tbeOnClick,'BtnStopClick');
  
  
  lblTimer= MyForm.AddNewLabel(pnlTimer,'lblTimer','0.0');
  lblTimer.StyledSettings = ssFamily;
  lblTimer.TextSettings.Font.Size=25;
  lblTimer.Align = alBottom;
  lblTimer.Margins.Left= 130;
  lblTimer.Height = 50;
  lblTimer.Width = 200;
  
  MyForm.Run;
}

Output:

See Also