Forum > Beginners

Wait/Delay

(1/2) > >>

mgarurumon:
Hello! I'm a student playing around with Lazarus Pascal. Previously, I did a little Dev-Pascal in middle school, but I'm just playing around now to refresh my memory in Lazarus. I'm a little confused on how how to delay/wait in Lazarus though? When I looked it up, there was something called Sleep, with a procedure already from SysUtils, but I'm not even sure how to use that... could anyone show me a very simple code or explain it to me in very simple instructions please?

What I had been aiming for would have been three periods appearing with a delay of 500 ms between each.
So,   . (delay) . (delay) . (delay)?

Thank you very much, and sorry if this is such a simple question!

tr_escape:
Delay and wait isn't implemented in fpc but you can use Sleep(ms); function for waiting.

But Sleep is really sleeper of your Operating System maybe you need a smart waiter like as:

procedure delay(const ms: double);
begin
  repeat
    application.ProcessMessages;
  until now > ms;
end;

This function gives a delay without stopping any gui operation also but you need to use if your application is must run other functions.



taazz:

--- Code: Delphi  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---...Sleep(500); ... For at least 500 milliseconds the application will be inactive after the allotted time has passed the OS will reschedule the application for execution in the next cycle. Keep in mind that on modern operating systems application are executed in turn for a small amount of time giving the impression of simultaneous execution. For the sake of simplicity  I'm ignoring multiple cores. If you need tight control on the time then you need to use a real time OS.

balazsszekely:
Or maybe this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure Delay(dt: DWORD);var  tc : DWORD;begin  tc := GetTickCount;  while (GetTickCount < tc + dt) and (not Application.Terminated) do    Application.ProcessMessages;end;

mgarurumon:
Thank you so much!  :)

Navigation

[0] Message Index

[#] Next page

Go to full version