我想在delphi中同时做两件事情,比如要同时运行两个定时器,,,,怎么用那个方法呢?
例如,让我们看这个简单的例子,这里有两个定时器,这些定时器连续运行,但我想同时运行定时器,,但是如何?
procedure TForm1.Button1Click(Sender: TObject);
begin
if Button1.Caption = 'START' then
begin
Timer1.Enabled := True;
Timer2.Enabled := True;
Button1.Caption := 'FINISH'
end
else if Button1.Caption = 'FINISH' then
begin
Timer1.Enabled := False;
Timer2.Enabled := False;
Button1.Caption := 'START';
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
i : integer;
begin
for i := 0 to 50 do
begin
Memo1.Lines.Add(IntToStr(i));
sleep(500);
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var
k : integer;
begin
for k := 0 to 50 do
begin
Memo2.Lines.Add(IntToStr(k));
sleep(500);
end;
end;
end.