IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

September Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingDelphi for W...Using Data   Print This     
Next Random Article Next Random Tidbit || Change Topic Random From All

Random Tidbit

Part of the mo. lesson in the Aug 08 Issue of Prestwood eMag
Delphi Code Snippet:
 A flashcard from our Delphi Flashcards Library
 A code snippet from our Delphi Code Snippets Page
Application.ProcessMessages

I always found the sleep command in ObjectPAL very useful. The following code does about the same thing in Delphi. It makes use of GetTickCount which is a Win32 API call that retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days.


procedure TUtils.Delay(MillisecondsDelay: Integer);
var
   FirstTickCount: LongInt;
begin
   FirstTickCount := GetTickCount;
   repeat 
       Application.ProcessMessages;
   until ((GetTickCount-FirstTickCount) >= Longint(MillisecondsDelay));
end;

Comments

1 Comments.
Share a thought or comment...
Comment 1 of 2
I would avoid having to re-cast the long-int in each iteration, and I would bullet-proof the tickmax value against a negative delay parameter.

The ProcessMessages call assures the sytem responds to other processes during the iteration.

procedure tutils.delay(const millisecondsdelay: integer);
var tickmax: longint;
begin
tickmax:=max(0,GetTickCount+millsecondsdelay);
repeat
Application.ProcessMessages
until GetTickCount>=tickmax;
end;
Posted 9 years ago

Comment 2 of 2

Nice addition Mark, thanks.

Posted 9 years ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1226A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #100786 Counter
10941
Since 4/2/2008
-
   Contact Us!
 
Have a question? Need our services? Contact us now.
--Mike Prestwood

Call: 916-726-5675

email: info@prestwood.com


Go ahead!   Use Us! Call: 916-726-5675 


©1995-2017 Prestwood IT Solutions.   [Security & Privacy]