unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TTimer=class(TThread)
protected
procedure Execute; override;
procedure DoExecute;
end;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
FTime:TTime;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var
TimerThread:TTimer;
procedure TTimer.Execute;
begin
While (not Terminated) do
begin
Synchronize(DoExecute);
Sleep(60000);//задержка минута
end;
end;
procedure TTimer.DoExecute;
begin
Form1.FTime:=Now;//текущее время
//какой то код вывода на экран
end;
procedure TForm1.Button1Click(Sender: TObject);//запуск потока
begin
TimerThread:=TTimer.Create(False);
end;
procedure TForm1.Button2Click(Sender: TObject);//закрытие потока
begin
TimerThread.FreeOnTerminate:=True;
TimerThread.Terminate;
TimerThread:=nil;
end;
end.