Recent

Author Topic: Delay  (Read 4421 times)

michoux

  • Full Member
  • ***
  • Posts: 112
Delay
« 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 ...                                         

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Delay
« Reply #1 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

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Delay
« Reply #2 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
« Last Edit: June 19, 2021, 09:31:13 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: Delay
« Reply #3 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.
« Last Edit: June 24, 2021, 07:22:40 pm by BobDog »

 

TinyPortal © 2005-2018