//调用方法 Delay(1000);
procedure TForm1.Delay(msecs: integer);
var
Tick: DWord;
Event: THandle;
begin
Event := CreateEvent(nil, False, False, nil);
try
Tick := GetTickCount + DWord(msecs);
while (msecs > 0) and (MsgWaitForMultipleObjects(1, Event, False, msecs,
QS_ALLINPUT) <> WAIT_TIMEOUT) do
begin
Application.ProcessMessages;
msecs := Tick - GetTickCount;
end;
finally
CloseHandle(Event);
end;
end;
//倒计时
var
Form1: TForm1;
TimeCount: Integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if Trim(Edit1.Text) <> '' then
Begin
TimeCount := Strtoint(Trim(Edit1.Text)) * 60;
Timer1.Enabled := True;
End;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label1.Caption := Format('%0.2d', [TimeCount div 60]) + ':' + Format('%0.2d', [TimeCount Mod 60]);
TimeCount := TimeCount - 1;
if TimeCount = 0 then
Begin
Application.Terminate;
End;
end;