From Clomosy Docs

No edit summary
No edit summary
Line 28: Line 28:
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.<br>
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.<br>


:'''TRObject Syntax'''
 
<pre>
<pre>
var
var
Line 105: Line 105:
   MyForm.Run;
   MyForm.Run;
}
}
</pre>
:'''Base Syntax'''
<pre>
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');
  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;
end;
</pre>
</pre>



Revision as of 13:01, 13 November 2024

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(xOwner:TComponent; xName:String; xInterval:Integer): 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.

Feature Use of Definition
TClTimer Timer1: TclTimer; A variable belonging to the TclTimer class is created.
AddNewTimer Timer1 = MyForm.AddNewTimer(MyForm,'Timer1',1000); // the action is triggered every 1 second. A new TclTimer is added to the form.
tbeOnTimer MyForm.AddNewEvent(Timer1,tbeOnTimer,'timerShow'); 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.
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.

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.


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