From Clomosy Docs

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 we have code that we want to run every second, we write it to the tbeOnTimer event of the TClTimer component. Then, if we set the component's Interval property to 1000, the code we wrote will be executed every second.

AddNewTimer(TComponent, xName, xMillisecond): TClTimer

TComponent : The variable name of the defined component is written. Here you should write the component variable name of whatever your component will be in.

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

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

Let's create a TclTimer.
1. Create a new project.

2. You need to define TclTimer on the form. To do this, you should add under the var parameter on the ide as follows. It is the name of your variable you typed at the beginning. You should define this as you want and add it as TclTimer.

var
GetTimer: TClTimer;

3. Add the TClTimer to the form. For this, you must add the begin end block and add it inside the form after the form is defined. By saying MyForm.AddNewTimer, we actually add to the form we have defined. Here, you need to add your form definition as whatever you wrote it.

GetTimer:= MyForm.AddNewTimer(MyForm,'GetTimer',1000); // the action is triggered every 1 second.

4. While defining the component, you can define it manually by typing. Another method is to write its shortcut. If you type "AddNewTimer" while the shortcut is in the code block, a pop-up menu will appear.

frameles

As soon as you click, the following block will come automatically.

AddNewTimer(xOwner:TComponent; xName:String; xInterval:Integer);

5. We gave the variable name while defining the TClTimer in var. Now when you add this in begin end you should use this variable name in all definitions. Your code will throw an error when you write these variable names incorrectly.

6. Now, if we want to activate the click feature of our TCLTimer component, we can do it with AddNewEvent. Here we should write tbeOnTimer as the 2nd parameter. In the last parameter, we should write the action that will be triggered when clicked.

MyForm.AddNewEvent(GetTimer,tbeOnTimer,'timerShow');

7. Below, the time to be triggered is written in the 3rd parameter at the time of calling with the AddNewTimer function. If we write the time as 0 here, the trigger will not occur at all. In this case, a trigger time can be given to the Interval property for triggering. Thus, even though it is 0, triggering with interval will still be provided.

Interval Property: This property specifies the intervals at which the timer component will be run. If the Interval is set to 1000, the timer will run every second. So 1000 means 1 second. If the Interval value is 500, the timer will run 2 times per second.

The following code show how to define the interval property of the timer component.

VariableValue.Interval := 1000;

8. Enabled Property: It is the property that the TClTimer component decides whether to run the codes or not. If the enabled property is true, the timer runs the codes at the desired times. If the Enabled property is false, the timer will not work.

In the codes below, the enabled property of the timer component is changed to true and false.

VariableValue.Enabled := True;
VariableValue.Enabled := False;


9. To tell you the truth, you have created a simple application that does nothing yet. Let's save and start using our project. You can save in one of two ways:
Click the save icon (the button in the upper right corner) or press Ctrl + S to save the project and see what you've done on the platforms now.

Example:
In the example, the chromometer was built using a timer. You can use it this way or you can use this component for any scheduling you want.

Base Syntax
 var
   MyForm:TclForm;
   GetTimer: TClTimer;
   GetStartTimerBtn,GetStopTimerBtn : TClProButton;
   duration, sn ,ss : Integer;
   lblTimer : TclLabel;
   lytTimer :TClLayout;
   pnlTimer :TClPanel;
 
 Procedure BtnStartClick;
 begin
   //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');
 End;
 
 procedure BtnStopClick;
 begin
   GetTimer.Enabled := False;
 end;
 
 procedure timerShow;
 begin
   Inc(duration);
   sn := (duration div 10);
   ss := (duration mod 10);
   lblTimer.Caption := IntToStr(sn)+'.'+IntToStr(ss);
 end;
 
 begin
   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');
   clComponent.SetupComponent(GetStartTimerBtn,'{"Align" : "Left",
   "Width" :100,"Height":40,"RoundHeight":2, "RoundWidth":2,"BorderColor":"#7A3E65","BorderWidth":2}');
   MyForm.AddNewEvent(GetStartTimerBtn,tbeOnClick,'BtnStartClick');
   
   GetStopTimerBtn := MyForm.AddNewProButton(lytTimer,'GetStopTimerBtn','Stop');
   clComponent.SetupComponent(GetStopTimerBtn,'{"Align" : "Right",
   "Width" :100,"Height":40,"RoundHeight":2, "RoundWidth":2,"BorderColor":"#7A3E65","BorderWidth":2}');
   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;
 end;
TRObject Syntax
 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');
   clComponent.SetupComponent(GetStartTimerBtn,'{"Align" : "Left",
   "Width" :100,"Height":40,"RoundHeight":2, "RoundWidth":2,"BorderColor":"#7A3E65","BorderWidth":2}');
   MyForm.AddNewEvent(GetStartTimerBtn,tbeOnClick,'BtnStartClick');
   
   GetStopTimerBtn = MyForm.AddNewProButton(lytTimer,'GetStopTimerBtn','Stop');
   clComponent.SetupComponent(GetStopTimerBtn,'{"Align" : "Right",
   "Width" :100,"Height":40,"RoundHeight":2, "RoundWidth":2,"BorderColor":"#7A3E65","BorderWidth":2}');
   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