?
Solved

Sleep / Delay in Delphi 1.0

Posted on 1997-10-29
6
Medium Priority
?
3,325 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 400 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 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