Solved

Sleep / Delay in Delphi 1.0

Posted on 1997-10-29
6
3,300 Views
Last Modified: 2010-10-05
Is there a command analogous to sleep() in Delphi 1.0?
0
Comment
Question by:mozack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

737 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