Solved

Sleep / Delay in Delphi 1.0

Posted on 1997-10-29
6
3,290 Views
Last Modified: 2010-10-05
Is there a command analogous to sleep() in Delphi 1.0?
0
Comment
Question by:mozack
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:fsanchez
ID: 1349123
No, but you can achieve it with this procedure:

procedure Sleep(const Millisec: Longint);
var
  Limit: Longint;
begin
  Limit := GetTickCount + Millisec;
  while GetTickCount < Limit do;
end;

GetTickCount is Windows API function that returns the number of milliseconds that have elapsed since Windows was started. If you don't want to freeze the message processing of the application you could do:

  while GetTickCount < Limit do
    Application.ProcessMessages;

but if there are many messages or some of they are slow, then you could lose some precision.
0
 

Author Comment

by:mozack
ID: 1349124
I really need a function that acts like sleep() (i.e. does not drain the CPU).
0
 

Author Comment

by:mozack
ID: 1349125
Also, I've reached the system limit for TTimer's, so I can't use a TTimer to implement the sleep.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1349126
Mozack,

Instead of counting on the TTimer to keep track of the ENTIRE amount of time, simply keep track of how many times it's been activated. For instance:

60000 (1 minute) for the TTimer and every time it activates increments a counter to increment the number of minutes counted until you reach the value (# of minutes) you want.

Good luck with you project
Pegasus
0
 

Author Comment

by:mozack
ID: 1349127
That's not quite what I'm looking for.  I've reached the system limit for the number of TTimer's the system can support at one time.  Several instances of the same application will be running at the same, and each one uses a few TTimer's.  Once a certain number of apps are started, I get a message saying -- Resource limit for Timers exceeded -- or some such message.  I'm at a point now where I can bring up the number of apps I need, but I can't add any more TTimers.
0
 
LVL 3

Accepted Solution

by:
Pegasus100397 earned 100 total points
ID: 1349128
Mozack,

I ran into the exact same problem about 2 months ago with too many apps using too many timers. My "fix" was to "Dual-purpose" a timer (actually 4 processes used the same timer). I needed each process to execute at a different amount of time and kept an array of Integers that would keep track of each time the timer activated. When the array values reached the desired count then it would call it's respective procedure.

Using timers in this way lets one timer handle the needs of many. For instance, set the timer for 1 minute (example)

On the first "tick" it increments all the array values [let's say 4 processes need to be tracked)

On the first minute, arrays[1] through array[4] are incremented by one. Process #1 needs to be fired every minute, so it's Array[1] is set back to 0 and it's respective procedure is fired off.

When the next minute rolls around, the arrays[1..4] are again incremented. Process #1 is again triggered (1 minute intervals) but by now Array[2] has reached "2" to Array[2] is set back to zero and it's process fired off as well.

While not the cleanest method of re-using the same timer for multiple processes, I find it works extemely well. Depending on how time-critical your application is, it may pay off to use this technique.

If this is not an acceptable answer then I'll quite down and let someone else have a gander at it :)

Good Luck with your project!
Pegasus
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question