Board index » cppbuilder » Hooking up an Event Handler function at Runtime

Hooking up an Event Handler function at Runtime

Is there a way to hook up, at runtime, the relationship between a VCL Event
and an EventHandler function?

For example, I create a TStringGrid at runtime.  I want to provide an
EventHandler for the OnDrawCell Event.  Obviously, this is a breeze when I
create my grid at designtime using the IDE, but I don't have that luxury in
my current scenario.  So,

How do I create the relationship between my EventHandler and the OnDrawCell
Event at runtime?  And I will add that I would like to avoid the MESSAGE_MAP
approach if at all possible...

Thanks in advance,
Brian

 

Re:Hooking up an Event Handler function at Runtime


    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
        TStringGrid *SG = new TStringGrid(this);
        SG->Parent = this;
        // set other properties as needed
        SG->OnDrawCell = StringGridDrawCell;
    }

    void __fastcall TForm1::StringGridDrawCell(TObject* Sender, long ACol,
long ARow, TRect Rect, TGridDrawState State)
    {
        // draw the cell as needed
    }

Don't forget to add the definition for StringGridDrawCell() in the form's
header file, in one of the "User declarations" sections.

Gambit

Quote
"Brian Plummer" <bplum...@hotmail.com> wrote in message

news:3d36000e_2@dnews...
Quote
> Is there a way to hook up, at runtime, the relationship between
> a VCL Event and an EventHandler function?

> For example, I create a TStringGrid at runtime.  I want to provide an
> EventHandler for the OnDrawCell Event.  Obviously, this is a breeze when I
> create my grid at designtime using the IDE, but I don't have that luxury
in
> my current scenario.

Other Threads