Delphi中进行延时的4种方法

Posted jijm123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Delphi中进行延时的4种方法相关的知识,希望对你有一定的参考价值。

 1、挂起,不占CPU
sleep
2、不挂起,占cpu
procedure Delay(msecs:integer);
var
FirstTickCount:longint;
begin
FirstTickCount:=GetTickCount;
repeat
Application.ProcessMessages;
until ((GetTickCount-FirstTickCount) >= Longint(msecs));
end;
3、定时器
procedure timerfun(handle:Thandle;msg:word;identer:word;dwtime:longword);stdcall;
begin
showmessage(‘到点了‘);
killtimer(handle,identer);//关闭定时器
end;

//其中的identer是定时器的句柄
procedure TForm1.Button1Click(Sender: TObject);
var
identer:integer;
begin
   identer:=settimer(0,0,2000,@timerfun);
   if identer=0 then exit; //定时器没有创建成功。
end;
4、不占CPU不挂起
function TForm1.HaveSigned(MaxWaitTime: Cardinal): Boolean;
var   I:Integer;
var   WaitedTime:Cardinal;
begin
          WaitedTime:=0;
          while      (WaitedTime
          begin
                  SleepEx(100,False);
                  Inc(WaitedTime,100);
                  Application.ProcessMessages ;
          end
end;

以上是关于Delphi中进行延时的4种方法的主要内容,如果未能解决你的问题,请参考以下文章

4种Delphi IDE的调试时查看内存的方法,太酷了!

怎么在delphi中读取Excel数据 转

delphi中将 4 个 Byte 合成 1 个 Integer 的五种方法

如何在 Delphi 中进行线程化的各种方式之间进行选择?

delphi运行时主界面卡死

delphi中调用.OCX怎样进行的?万分感谢!