码迷,mamicode.com
首页 > Windows程序 > 详细

[转]Delphi中进行延时的4种方法

时间:2014-12-29 00:52:46      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:

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<MaxWaitTime)   do
          begin
                  SleepEx(100,False);
                  Inc(WaitedTime,100);
                  Application.ProcessMessages ;
          end
end;

[转]Delphi中进行延时的4种方法

标签:

原文地址:http://www.cnblogs.com/go-jzg/p/4190853.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!