Solved

timer component how to use it?

Posted on 2006-07-04
1
311 Views
Last Modified: 2011-04-14
my program has a loop in the FormCreate (the main form) and my program gets stuck in the loop. the loop works and  everything no problem with the loop, but the... form doesn't create itself untill the loop is over... and the loop is the most important part of the program. i was told to use a timer, or gaming loops (don't know one thing about either of them) so i have the timer function... i need someone tho show me how to use it.

void __fastcall TPMmainForm::Timer1Timer(TObject *Sender)
{

}
0
Comment
Question by:crims
1 Comment
 
LVL 1

Accepted Solution

by:
lozherbert earned 200 total points
ID: 17041761
I guess from the looks of the function syntax you're using Borland Builder...

What you want to do is to simply copy and paste your loop code into the Timer1Timer function.

You also need to add an extra bit though and I'll explain why.

When you set up a timer, it will call the Timer event function (Timer1Timer(TObject *Sender) every x milliseconds.

You can specify when the timer gets called by changing Timer1->Interval either programmatically or in the IDE.
For example, if you want it to call the function in 5 seconds.  Set interval to 5000 which is 5 * 1000ms.  If you want it called in 3 seconds, set it to 3000.

If you don't want the function to be called every x milliseconds, you can tell it to disable the timer when it's called.  That way it will only be called once unless you re-enable it in code. e.g.

void __fastcall TPMmainForm::Timer1Timer(TObject *Sender)
{
   Timer1->Enabled = false;
   
   // ... Your Loop code here...
}

In the IDE you can specify whether the Timer1->Enabled property is true.  If you set it to true, it will be active as soon as your program is launched and will execute the event after the interval.  The alternative is to set it to true when the form is being shown by using the FormShow event handler...

void __fastcall TPMmainForm::FormShow(TObject *Sender)
{
   Timer1->Enabled = true;
}

Hope that helps.  
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Basic Java Case or If-Else statement... 3 64
Definitions and default visual studio colors 5 74
Adding a countdown to HTA 12 92
Java array 10 55
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

685 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