当前位置:网站首页>[3.delphi common components] 7 timer

[3.delphi common components] 7 timer

2022-06-11 02:12:00 Janeb1018

7. timer

timer (Timer) An event can be generated in an application at repeated intervals . Is a non visual component . The main attributes are as follows :

attribute explain
Enabled The value of this property is True when , start-up , by False when , Suspend work
Interval Set the period triggered by the timer ( Company :ms)

Major events :

event explain
OnTimer The event is Interval The frequency of property setting is triggered

Example : Electronic clock , At the same time, set the square position of the scroll bar to the second value of the current time , The interface is as follows :

 

The program code is as follows :

procedure TForm1.RadioButton1Click(Sender: TObject);
begin
  Timer1Timer(Sender);
end;
​
procedure TForm1.RadioButton2Click(Sender: TObject);
begin
  Timer1Timer(Sender);
end;
​
procedure TForm1.Timer1Timer(Sender: TObject);
var
  h, m, s, ms: Word;
  CurrentTime: TDateTime;
begin
  //  Electronic clock 
  CurrentTime := time;
  if RadioButton1.Checked then
    Label2.Caption := formatdatetime('ampmhh:nn:ss', CurrentTime)
  else
    Label2.Caption := formatdatetime('hh:nn:ss', CurrentTime);
​
  DecodeTime(CurrentTime, h, m, s, ms);
  ScrollBar1.Position := s;
end;
原网站

版权声明
本文为[Janeb1018]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020617548254.html