延迟执行

//调用方法 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;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值