您好,欢迎来到刀刀网。
搜索
您的当前位置:首页delphi延时的4种方法

delphi延时的4种方法

来源:刀刀网
delphi延时的4种方法有时候我们需要让程序暂停一段时间,这就要用到程序延时了。//////////////////挂起,不占CPUsleep

//////////////////不挂起,占cpu

procedureDelay(msecs:integer);var

FirstTickCount:longint;begin

FirstTickCount:=GetTickCount;repeat

Application.ProcessMessages;

until((GetTickCount-FirstTickCount)>=Longint(msecs));end;

//////////////////////////////////////////定时器

proceduretimerfun(handle:Thandle;msg:word;identer:word;dwtime:longword);stdcall;begin

showmessage('到点了');

killtimer(handle,identer);//关闭定时器end;

//其中的identer是定时器的句柄

procedureTForm1.Button1Click(Sender:TObject);var

identer:integer;begin

identer:=settimer(0,0,2000,@timerfun);

ifidenter=0thenexit;//定时器没有创建成功。end;

//////////////////////////////////////////////////不占CPU不挂起functionTForm1.HaveSigned(MaxWaitTime:Cardinal):Boolean;varI:Integer;

varWaitedTime:Cardinal;begin

WaitedTime:=0;while(WaitedTimeSleepEx(100,False);Inc(WaitedTime,100);

Application.ProcessMessages;end

end;

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- gamedaodao.com 版权所有 湘ICP备2022005869号-6

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务