delphi延时4种方法


本文整理自网络,侵删。

 //////////////////挂起,不占CPU
sleep
//////////////////不挂起,占cpu
procedure Delay(msecs:integer);
var
FirstTickCount:longint;
begin
FirstTickCount:=GetTickCount;
repeat
Application.ProcessMessages;
until ((GetTickCount-FirstTickCount) >= Longint(msecs));
end;
////////////////////////////////////////// 定时器
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;
////////////////////////////////////////////////// 不占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中基于内容检测图片格式(非扩展名)

Delphi 跳出for循环

Delphi android / ios应用程序中使用tgeocoder类进行反向地理编码(从位置信息中获取地址)

Delphi 获取系统的硬盘分区及使用信息

Delphi 利用windows api判断文件共享锁定状态

Delphi通过调用com对象实现更改桌面壁纸

Delphi中json回车换行符转义

Delphi文件捆绑器

Delphi 枚举消息钩子的代码

Delphi 网上获取北京时间 tinifile.readsection 方法在 android 下的应用及各种字符编码问题

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...