Solved

timer component how to use it?

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This is about my first experience with programming Arduino.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?

739 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