您的位置:首页 > 编程语言 > Delphi

Delphi中GetTickCount函数的使用

2016-12-06 18:37 621 查看
【函数名】 GetTickCount

【库名】 kernel32

【说明】 用于获取自windows启动以来经历的时间长度(毫秒)

【返回值】 Long,以毫秒为单位的windows运行时间

通常用来计算某个操作所使用的时间: 

Start:=GetTickCount; 

...//执行耗时的操作

Stop:=GetTickCount; 
TimeUsed:=(Stop-Start)/1000; //使用了xxx秒

也可以用来做延时程序:

Procedure   TForm1.Delay(Msecs:   Integer);
var
firstTickCount   :   real;
begin
firstTickCount   :=   GetTickCount;
Repeat
Until   ((GetTickCount   -   firstTickCount)   >=   longInt(Msecs));
end;


还可以用来判断和控制隔一段时间才执行一次的方法:

if ((GetTickCount - MktHQRefreshTime) div 1000) >= SSConfig.HqRefreshTime  then //根据配置的时间回扫挂单
begin
MktHQRefreshTime := GetTickCount;
HSGDTradeTask(con);
t4 := Now;
AddLog(Format('行情回扫挂单,总耗时%5.2f ms', [(t4 - t3) * MSecsPerDay ]));
end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: