TTimer组件属性
Enabled属性
该属性控制TTimer组件是否周期性的产生OnTimer事件,为True,则产生周期性事件。false则不产生
示例
procedure TForm1.FormCreate(Sender: TObject); begin timer1.Enabled:= False; Timer2.Enabled:= False; end; procedure TForm1.Timer1Timer(Sender: TObject); begin Edit1.Text:= IntToStr(strtoint(Edit1.text)+1); end; procedure TForm1.Button1Click(Sender: TObject); begin Timer1.Enabled:=True; Caption:=‘计时开始‘; Timer2.Enabled:= False; end; procedure TForm1.Timer2Timer(Sender: TObject); begin Edit2.Text:= IntToStr(strtoint(Edit2.text)-1); end; procedure TForm1.Button2Click(Sender: TObject); begin Timer2.Enabled:= True; Caption:=‘倒计时开始‘; Timer1.Enabled:=False; end; end.
示例:显示时间
procedure TForm1.Timer1Timer(Sender: TObject); begin label1.Caption:= DateTimeToStr(Now()); end;