Solved

Sleep / Delay in Delphi 1.0

Posted on 1997-10-29
6
3,265 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now