Solved

timer component how to use it?

Posted on 2006-07-04
1
279 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
This is an explanation of a simple data model to help parse a JSON feed
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

15 Experts available now in Live!

Get 1:1 Help Now