Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Waiting in C++ Builder

Status
Not open for further replies.

Maingoka

Programmer
Mar 25, 2001
3
0
0
MG
Hi!
How to make a function wait for x seconds before doing something??
Example: When I click a button: in the onmousedown, I want to wait 1 second before it executes a function
Thank you

Maingoka
 
#include <dos.h>

long delay = 500; // 5 sec.,delay in hundred of second
struct time oldt;
struct time newt;

gettime(&oldt);

for(;;)
{
gettime(&newt);
long t = (newt.ti_hund-oldt.ti_hund) +
100*(newt.ti_sec - oldt.ti_sec) +
6000*(newt.ti_min - oldt.ti_min);
if(t >= delay)
break;
}
 
Sleep(number of milliseconds to wait)
suspends the execution of your program.

Or you use a TimerComponent and with your mousedownevent you enable the timer (Timer->Enabled=true)
In your TimerEvent (Timer->OnTimer)you first set the Timer->Enabled to false (otherwise you keep on triggering your event) and then you put the code you want to execute after 1 second.

Personally I would prefer the second solution, in a windows environment I find it a bit tricky to really suspend the execution of a program,but it works.


Wim Vanherp
Wim.Vanherp@myself.com
 
use
Sleep(NumberOfMillisecons);//is much easier. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top