Lazarus

Programming => General => Topic started by: michoux on June 18, 2021, 05:06:56 pm

Title: Delay
Post by: michoux on June 18, 2021, 05:06:56 pm
Hello,

I am using follwoing code to make a delay of a seconds ...


Code: Pascal  [Select][+][-]
  1.  
  2. procedure Delay1(TickTime : Integer);
  3.  var
  4.  Past: longint;
  5.  begin
  6.  
  7.  Past := GetTickCount;
  8.  repeat
  9.  application.ProcessMessages;
  10.  Until (GetTickCount - Past) >= longint(TickTime);
  11. end;
  12.  
                       

It works om my laptop win10 but not on second laptop also win10, delay is simply not followed ...                                         
Title: Re: Delay
Post by: jamie on June 18, 2021, 10:40:39 pm
How small of a Tick value are you passing to it ?

Maybe your failing laptop is slow ?
Title: Re: Delay
Post by: winni on June 18, 2021, 11:18:31 pm
Hi!

For test reasons add a Label and an Integer i.
This code will schow you every second the progress


Code: Pascal  [Select][+][-]
  1. procedure Delay1(TickTime : Integer);
  2.  var
  3.  Past: longint;
  4.  i : Integer =0;
  5.  begin
  6.  
  7.  Past := GetTickCount;
  8.  repeat
  9.  inc(i);
  10.  if i mod 1000 = 0 then Label1.Caption := IntToStr(i);
  11.  application.ProcessMessages;
  12.  Until (GetTickCount - Past) >= longint(TickTime);
  13. end;
  14.  


Winni
Title: Re: Delay
Post by: Jurassic Pork on June 19, 2021, 09:25:20 am
Hello,
It works om my laptop win10 but not on second laptop also win10, delay is simply not followed ...                                       
have you the same version of lazarus and fpc on the two laptops?  32 bits ? 64 bits ?
Quote
GetTickCount (deprecated)
Get tick count (32-bit, deprecated)

Declaration
Source position: sysutilh.inc line 28

function GetTickCount: LongWord;

Description
GetTickCount returns an increasing clock tick count in milliseconds. It is useful for time measurements, but no assumptions should be made as to the interval between the ticks. This function is provided for Delphi compatibility, use GetTickCount64 instead.

Quote
GetTickCount64
Get tick count (64-bit)

Declaration
Source position: sysutilh.inc line 29

function GetTickCount64: QWord;

Description
GetTickCount64 returns an increasing clock tick count in milliseconds. It is useful for time measurements, but no assumptions should be made as to the interval between the ticks.

Friendly, J.P
Title: Re: Delay
Post by: BobDog on June 24, 2021, 06:56:12 pm
Call it sleep.
Code: Pascal  [Select][+][-]
  1.  
  2.  
  3.  program sleep;
  4.      uses
  5. SysUtils,DateUtils;
  6.  
  7. procedure sleep(t:integer);
  8. var
  9. D1: TDateTime;
  10. begin
  11.   D1:=now;
  12.   repeat
  13.   until MilliSecondsBetween(now,D1) >= t
  14. end;
  15.  
  16.  var i:integer;
  17. begin
  18. for i:=1 to 10 do
  19. begin
  20. writeln(TimeToStr(Time)) ;
  21. sleep(1000) ;
  22. end;
  23. writeln('Press enter to end . . .');
  24. readln;
  25. end.
TinyPortal © 2005-2018