Pascal 已执行函数的计时器返回零
linux上的endtime返回结果Pascal 已执行函数的计时器返回零,pascal,freepascal,Pascal,Freepascal,linux上的endtime返回结果0。对于给定的睡眠功能,它应该是以毫秒为单位的返回数。在GUI的标签上显示0 以下是代码: var starttime: longint; var endtime: longint; function GetTickCount : DWORD; begin {$IFDEF MSWINDOWS} Result := Windows.GetTickCount mod High(LongInt); {$ELSE} Result := GetTickCoun
0
。对于给定的睡眠功能,它应该是以毫秒为单位的返回数。在GUI的标签上显示0
以下是代码:
var starttime: longint;
var endtime: longint;
function GetTickCount : DWORD;
begin
{$IFDEF MSWINDOWS}
Result := Windows.GetTickCount mod High(LongInt);
{$ELSE}
Result := GetTickCount mod High(LongInt);
{$ENDIF}
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
starttime:=getTickCount;
// something do...
Sleep(1500); // sleep in miliseconds, works!
endtime:=getTickCount-starttime;
Label1.Caption:=inttostr(endtime); // returns 0 ?
end;
gettickcount函数{$else}中的gettickcount被解释为过程的返回值。(德尔菲结果) 根据模式的不同,这可能导致永久递归 解决方案:就像在windows中一样,使用unitname进行限定
{$else}
Result := SysUtils.GetTickCount mod High(LongInt);
在Linux上,如果我像前面提到的那样更改为,它将不起作用。标识符没有找到“GetTickCount”。事实上,这似乎是一个主干(开发)功能,尚未发布版本。我也用Lazarus在Windows上测试过,似乎在Windows上不起作用。是否有其他方法来实现计数器?