Creating Component with Timer in it.

Hi folks.

Have anybody tryed to create a component with a timer in it?
My problem is how to control the event handler OnTimer.
I need to assign my own function to the event handler in my component.
In a form it is easy, but whitout a form....

Hope to here from someone.

Ingvar
using Borland Developer Studio 2006 (C++)

Comments

  • : Hi folks.
    :
    : Have anybody tryed to create a component with a timer in it?
    : My problem is how to control the event handler OnTimer.
    : I need to assign my own function to the event handler in my component.
    : In a form it is easy, but whitout a form....
    :
    : Hope to here from someone.
    :
    : Ingvar
    : using Borland Developer Studio 2006 (C++)
    :
    Hi Ingvar,

    what error does your solution give you?

    Setting the Event handler at run-time (as opposed to design-time) is discussed here: http://www.codepedia.com/1/CppVclEvent if that is the problem.

    See ya,
    bilderbikkel

  • Hi bilderbikkel

    Thank's for helping out.

    The example at the Codepedia worked for me.
    But not in my own component.

    The cpp file
    [code]
    TimerS = new TTimer(this); // New Timer
    TimerS->Interval = 800;
    TimerS->OnTimer = NewOnTimer; // Here i got the error
    //[C++ Error] AskPanel.cpp(169): E2034 Cannot convert 'void (_fastcall * (_closure )(TComponent *))(TComponent *)' to 'TNotifyEvent'

    TimerS->Enabled = true;
    [/code]

    The function
    [code]
    void __fastcall AskPanel::NewOnTimer(TComponent* Sender)
    {
    LedArrow->Active = !LedArrow->Active; // flashing arrow
    }
    [/code]
    The hpp file
    [code]
    private:
    TTimer *TimerS;
    public:
    void __fastcall NewOnTimer(TComponent* Sender);
    [/code]

  • : Hi bilderbikkel
    :
    : Thank's for helping out.
    :
    : The example at the Codepedia worked for me.
    : But not in my own component.
    :
    : The cpp file
    : [code]
    : TimerS = new TTimer(this); // New Timer
    : TimerS->Interval = 800;
    : TimerS->OnTimer = NewOnTimer; // Here i got the error
    : //[C++ Error] AskPanel.cpp(169): E2034 Cannot convert 'void (_fastcall * (_closure )(TComponent *))(TComponent *)' to 'TNotifyEvent'
    :
    : TimerS->Enabled = true;
    : [/code]
    :
    : The function
    : [code]
    : void __fastcall AskPanel::NewOnTimer(TComponent* Sender)
    : {
    : LedArrow->Active = !LedArrow->Active; // flashing arrow
    : }
    : [/code]
    : The hpp file
    : [code]
    : private:
    : TTimer *TimerS;
    : public:
    : void __fastcall NewOnTimer(TComponent* Sender);
    : [/code]
    :
    :
    Hi, I see you face the same problems as I already did. I'll try to figure it out as soon as I can...

    See ya,
    bilderbikkel

  • Hi bilderbikkel

    Thank you. It's very kind of you.

    Don't forget to celebrate the easter.

    Here in Sweden we eat eggs and hearing and
    of course snaps(alcohol).

    Ingvar




  • : Hi bilderbikkel

    I found a solution.
    This worked for me.
    [code]
    Timer = new TTimer(this);
    Timer->Interval = 800;
    Timer->OnTimer = (TNotifyEvent) &NyOnTimer;
    Timer->Enabled = true;

    [/code]
    [code]
    void __fastcall TIngvarPanel::NyOnTimer(TComponent* Sender)
    {
    ..... Do some stuff .....
    }
    [/code]
    Have a nice day.
    Ingvar

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories