Solved

timer component how to use it?

Posted on 2006-07-04
1
322 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

632 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