Board index » cppbuilder » TTimer created in Runtime not working

TTimer created in Runtime not working

My source codes look kind like this:
MyClass::MyClass()
{
MyTimer= new TTimer( NULL);        // Don't know what to put as TComponent
MyTimer->Enabled= false;
MyTimer->OnTimer= MyRoutine;

Quote
}

// Somewhere in the class MyTimer->Enabled= true

void __fastcall MyClass::MyRoutine( TObject *Sender)
{
MyTimer->Enabled= false;

// Some calculations for x
MyTimer->Interval= x;

MyTimer->Enabled= true;

Quote
}

After the timer is enabled the program doesn't enter the MyRoutine at all.

Phuoc Can HUA

 

Re:TTimer created in Runtime not working


Where are you creating the MyClass instance to begin with?  Is it in the
context of the main VCL thread?  If not, does the secondary thread running
the MyClass instance have its own message queue?  If not, then the timer
won't work, because TTimer is a message-based timer.

Gambit

"Phuoc Can HUA" <home-a-t-huaonline-d-o-t-com> wrote in message
news:3da22e8b$1@newsgroups.borland.com...

Quote
> After the timer is enabled the program doesn't enter the MyRoutine at all.

Re:TTimer created in Runtime not working


The object of the class is generated in the main Form and the timer is
enabled via a method in the class.

"Remy Lebeau (TeamB)" <gambi...@yahoo.com> wrote in message
news:3da236fc$1@newsgroups.borland.com...

Quote
> Where are you creating the MyClass instance to begin with?  Is it in the
> context of the main VCL thread?  If not, does the secondary thread running
> the MyClass instance have its own message queue?  If not, then the timer
> won't work, because TTimer is a message-based timer.

> Gambit

> "Phuoc Can HUA" <home-a-t-huaonline-d-o-t-com> wrote in message
> news:3da22e8b$1@newsgroups.borland.com...

> > After the timer is enabled the program doesn't enter the MyRoutine at
all.

Re:TTimer created in Runtime not working


Have you verified that you are, in fact, setting the Enabled property to
true?  How exactly are you instantiating and using the class?

Gambit

"Phuoc Can HUA" <home-a-t-huaonline-d-o-t-com> wrote in message
news:3da23ab5$1@newsgroups.borland.com...

Quote
> The object of the class is generated in the main Form
> and the timer is enabled via a method in the class.

Re:TTimer created in Runtime not working


// Main Form
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button1Click(TObject *Sender)
{
KarMidi Song("test1.mid");
Song.Play();

Quote
}

// My Class
//--------------------------------------------------------------------------
-
KarMidi::KarMidi( String _FName)
{
// Loading MIDI Events
...

EvtTimer= new TTimer( NULL);
EvtTimer->Enabled= false;
EvtTimer->OnTimer= PlayEvent;

Quote
}

//--------------------------------------------------------------------------
-
void    KarMidi::Play()
{
...
EvtTimer->Enabled= true;

Quote
}

//--------------------------------------------------------------------------
-
void __fastcall KarMidi::PlayEvent(TObject *Sender)
{
EvtTimer->Enabled= false;

...

if( CurEvent->next)
{       CurEvent= CurEvent->next;
        EvtTimer->Interval= 100;        // fixed for test purpose
        EvtTimer->Enabled= true;

Quote
}
}

Phuoc Can HUA

"Remy Lebeau (TeamB)" <gambi...@yahoo.com> wrote in message
news:3da2661e@newsgroups.borland.com...

Quote
> Have you verified that you are, in fact, setting the Enabled property to
> true?  How exactly are you instantiating and using the class?

> Gambit

Other Threads