Question

On linux endtime return results 0. It should be return number in miliseconds for given sleep function. On label on GUI it shows 0.

Here is code:

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;
Was it helpful?

Solution

The gettickcount in the {$else} of the gettickcount function is interpreted as the return value of a procedure. (result in Delphi)

Depending on mode, this might lead to eternal recursion

Solution: just like in the windows case, qualify with unitname so

   {$else}
        Result := SysUtils.GetTickCount mod High(LongInt);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top