Board index » cppbuilder » pointer to event handler

pointer to event handler


2006-08-24 05:10:24 AM
cppbuilder37
Hi all,
I need to pass a pointer of an event handler to a member function of a form.
when I add "_closure" keyword in the poiter definition, I got lots os
errors. Would you please let me know where shall I put the "_closure"
keyword in the below definition (the last parameter)?
------------------------------------
void __fastcall TForm1::UserDefinedRelationListKeyDown(TObject *Sender, bool
IsNP, WORD &Key,
TShiftState Shift, TTntComboBox *FocusObject, TButton *AddEditButton,
void (_fastcall *ClickFunction)(TObject *))
------------------------------------
Thank you,
Mehrdad
 
 

Re:pointer to event handler

"M. Noroozi Eghbali" < XXXX@XXXXX.COM >wrote in message
Quote
I need to pass a pointer of an event handler to a member function of a
form. when I add "_closure" keyword in the poiter definition, I got lots
os errors.
What errors exactly?
Quote
Would you please let me know where shall I put the "_closure" keyword in
the below definition (the last parameter)?
Use a typedef to make it clearer:
typedef void __fastcall (__closure *TMyEvent)(TObject *);
void __fastcall TForm1::UserDefinedRelationListKeyDown(TObject *Sender,
bool IsNP, WORD &Key, TShiftState Shift, TTntComboBox *FocusObject, TButton
*AddEditButton, TMyEvent ClickFunction);
Even better, the VCL already has its own TNotifyEvent type that has that
same signature, so there is no need to use your own typedef (unless you want
an event with custom parameters), ie:
void __fastcall TForm1::UserDefinedRelationListKeyDown(TObject *Sender,
bool IsNP, WORD &Key, TShiftState Shift, TTntComboBox *FocusObject, TButton
*AddEditButton, TNotifyEvent ClickFunction);
Gambit
 

Re:pointer to event handler

Thank you Remy,
Your solution (typedef) is working fine :-)
Regards,
Mehrdad
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"M. Noroozi Eghbali" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>I need to pass a pointer of an event handler to a member function of a
>form. when I add "_closure" keyword in the poiter definition, I got lots
>os errors.

What errors exactly?

>Would you please let me know where shall I put the "_closure" keyword in
the below definition (the last parameter)?

Use a typedef to make it clearer:

typedef void __fastcall (__closure *TMyEvent)(TObject *);

void __fastcall TForm1::UserDefinedRelationListKeyDown(TObject *Sender,
bool IsNP, WORD &Key, TShiftState Shift, TTntComboBox *FocusObject,
TButton
*AddEditButton, TMyEvent ClickFunction);

Even better, the VCL already has its own TNotifyEvent type that has that
same signature, so there is no need to use your own typedef (unless you
want
an event with custom parameters), ie:

void __fastcall TForm1::UserDefinedRelationListKeyDown(TObject *Sender,
bool IsNP, WORD &Key, TShiftState Shift, TTntComboBox *FocusObject,
TButton
*AddEditButton, TNotifyEvent ClickFunction);


Gambit


 

{smallsort}