Solved

Sleep / Delay in Delphi 1.0

Posted on 1997-10-29
6
3,272 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 284
ddeman not working in activex 3 92
Wininet read php file from internet issue 6 80
FMX StringGrid1->Canvas->FillRect Problem 3 127
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

930 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

14 Experts available now in Live!

Get 1:1 Help Now