Solved

similar sleep() function

Posted on 2000-04-15
16
173 Views
Last Modified: 2010-04-04
is there an api call or so which delays the processing od the next command, the next line of code. i mean, i need a function which delays eg. the drawing on screen of a timer, but all the other timers should remain working.
0
Comment
Question by:geoka
  • 4
  • 4
  • 4
  • +3
16 Comments
 
LVL 10

Expert Comment

by:ptmcomp
ID: 2719330
Hi geoka
Create a second thread and use there Sleep() to delay your code (don't call Synchonize!). Proceed the code that you don't want to slow down in the first thread.
ptm.
0
 
LVL 5

Expert Comment

by:heathprovost
ID: 2719336
not sure I understand the question...  Why wont sleep() suffice?  What do you mean "drawing on screen of a timer"?  I dont really understand the question, but the probably answer is to use a seperate thread to handle this "delayed drawing" stuff.  That way none of the other code in the program would be affected by this thread being in a "sleep" state.  Maybe you can ellaborate further

Heath
0
 
LVL 15

Expert Comment

by:simonet
ID: 2719373
Application.processmessages is the answer you need.

Just call it within a loop, like this:

for i:=1 to 1000 do
  application.processmessages;



Alex
0
 
LVL 20

Accepted Solution

by:
Madshi earned 50 total points
ID: 2720211
Alex is right. But I would suggest using GetTickCount to realize a specific delay time. Something like this:

procedure Delay(ms: dword);
var dw : dword;
begin
  dw := GetTickCount;
  repeat
    Application.ProcessMessages;
  until GetTickCount - dw > ms;
end;

But: This pushes the CPU to 100%. You could also try to add Sleep(10) before Application.ProcessMessages. Then the CPU doesn't run with 100%.

Regards, Madshi.
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 2720311
Application.ProcessMessages is a ugly hack, isn't it?
ptm.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2720367
No, it's no hack. It's a simple message loop. If you want to delay the current program flow, but nevertheless want to handle messages, a message loop is the one and only possibility.
0
 

Author Comment

by:geoka
ID: 2722100
emm.. i just recognized that i would not understand my question either, if i didn't know the problem.
the second go:
every 5 seconds a timer checks wether there are new messages to get, if there is a new message, it gets it, and executes an internal procedure, which is definded in the message. i wanted to make the code small so i did it that way: if the procedure, i called, should open the cd-drive, my code lookes like:

procedure opencd(l:integer);
begin;
  ;//the code which opens the cd-drive
  sleep(l);
  ;//the code which closes the cd-drive
end;

the next message disables e.g. ctrl+alt+entf, but i do not even get the message, because sleep(l); stopps the whole appliaction.
okay.
if i had understood right, then i could put every call into a seperste thread, and sleep(l); will only stopp the processing of the thread ???
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2722131
>> if i had understood right, then i could put every call into a seperste thread, and sleep(l); will only stopp the processing of the thread ???

Sleep definately only makes the current thread sleep. All other threads of your process run further. I still didn't understand completely what you want to do. Perhaps threads is one solution, another one would be to use Application.ProcessMessages instead of 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 10

Expert Comment

by:ptmcomp
ID: 2724269
Yes, I think we can only help you, if you tell us what you want to do. Perhaps there is a completely diffrent solution you never thought about...
ptm.
0
 

Author Comment

by:geoka
ID: 2726116
emm_ the app i'm writing doesn't do more than descripted above.
0
 
LVL 3

Expert Comment

by:f15iaf
ID: 2735732
procedure sleep(t:integer;{milisec});
var
   tt:integer;
begin
     tt:=gettickcount;
     while((tt-gettickcount)<t)do;
end;
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2735896
And another new expert! Welcome, f15iaf...   :-)

May I friendly request something? Here in the Delphi forum it is common practice to lock questions with an answer only if you are the first expert in the thread, or if all other comments are evidently wrong. Otherwise it is usual to post a *comment* only. This way the questioner can later choose easily which expert helped most. Thank you for listening...   (-:

Regards, Madshi.
0
 

Author Comment

by:geoka
ID: 2736139
this sets the cpu-power to 100%, not very helpful. the solution with creating threads seems better to me.
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 2737749
Hi geoka
Could you describe us, what you excatly want to delay? The drawing of your own app?
0
 
LVL 15

Expert Comment

by:simonet
ID: 2738198
Creating threads won't help yo ua bit.

Why don't you elaborate a little bit more on what you're trying to achieve?
0
 

Author Comment

by:geoka
ID: 2830273
wasn't exactely what i was looking for, but of course big thx...
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 XE10, MySQL Query 4 127
How to open a new windows chrome resized and disabled the toolbar? 3 82
QRReport  TQrmemo vertical stretching 1 42
DBGrid or StringGrid ? 6 71
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…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

895 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

17 Experts available now in Live!

Get 1:1 Help Now