Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

timer component how to use it?

Posted on 2006-07-04
1
Medium Priority
?
328 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 800 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

704 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