Board index » cppbuilder » console app., vcl component Timer, event handler TTimer::OnTimer()

console app., vcl component Timer, event handler TTimer::OnTimer()

Hello, All!
I'm writing a console application with vcl component Timer.
Help me to write event handler TTimer::OnTimer().
 

Re:console app., vcl component Timer, event handler TTimer::OnTimer()


Quote
Shakutin Kirill <shak...@mail.ru> wrote in message news:3c2b35d6_1@dnews...
> Hello, All!
> I'm writing a console application with vcl component Timer.
> Help me to write event handler TTimer::OnTimer().

Easy job:

void __fastcall TimerHandler(TObject *Sender)
{
   // Do whatever you have to do

Quote
}

/*----------------------------*/
in the main function:

TTimer *MyTimer = new TTimer(NULL);
MyTimer->OnTimer = TimerHandler;
MyTimer->Interval = xxx;  // xxx is the interval in msec
MyTimer->Enabled = True;  // Launch it
...
...
getch();
MyTimer->Enabled = False;  // Stop it

// At the end of the program
delete MyTimer;  // Mandatory since MyTimer does not have an owner
/*----------------------------*/

To be honest I haven't tried this code in a console application but it works
in a GUI program. Have a try

Alex

Re:console app., vcl component Timer, event handler TTimer::OnTimer()


Hello, Alex!
You wrote  on Thu, 27 Dec 2001 21:10:42 +0100:
[skiped]
AR> in the main function:

AR> TTimer *MyTimer = new TTimer(NULL);
AR> MyTimer->OnTimer = TimerHandler;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[C++ Error] Unit1.cpp(24): E2034 Cannot convert 'void (_fastcall *)(TObject
*)' to 'void (_fastcall * (_closure )(TObject *))(TObject *)'
do you now how to perform type conversion

With best regards, Shakutin Kirill.  E-mail: shak...@mail.ru

Re:console app., vcl component Timer, event handler TTimer::OnTimer()


Quote
"Shakutin Kirill" <shak...@mail.ru> writes:
> Hello, Alex!
> You wrote  on Thu, 27 Dec 2001 21:10:42 +0100:
> [skiped]
> AR> in the main function:

> AR> TTimer *MyTimer = new TTimer(NULL);
> AR> MyTimer->OnTimer = TimerHandler;
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> [C++ Error] Unit1.cpp(24): E2034 Cannot convert 'void (_fastcall *)(TObject
> *)' to 'void (_fastcall * (_closure )(TObject *))(TObject *)'
> do you now how to perform type conversion

It looks to me from the error that your TimerHandler is not a member
of a class.  It _must_ be a class member and not a free-standing function.

If this isn't it, perhaps you could post the offending code (minimized
to the greatest possible extent that still shows the error.)

--
Chris(TeamB);

Re:console app., vcl component Timer, event handler TTimer::OnTimer()


Hello,

    I had a similar problem when I tried to add an event to some
SpeedButtons I created at runtime. To solve the problem I put the event
declaration in the Form class that the buttons would eventually be on, and
assigned the handler like this:

<code>
MyTimer->OnTimer = TForm1->TimeHandler;
</code>

    In your case you would want to substitute TForm1 with whatever class you
added the function to.

HTH

Joe

Quote
"Shakutin Kirill" <shak...@mail.ru> wrote in message

news:3c2c7a02_2@dnews...
Quote
> Hello, Alex!
> You wrote  on Thu, 27 Dec 2001 21:10:42 +0100:
> [skiped]
> AR> in the main function:

> AR> TTimer *MyTimer = new TTimer(NULL);
> AR> MyTimer->OnTimer = TimerHandler;
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> [C++ Error] Unit1.cpp(24): E2034 Cannot convert 'void (_fastcall
*)(TObject
> *)' to 'void (_fastcall * (_closure )(TObject *))(TObject *)'
> do you now how to perform type conversion

> With best regards, Shakutin Kirill.  E-mail: shak...@mail.ru

Other Threads