Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing a function as a parameter to use as an event

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello All,

I'm trying to make an array of labels , but I need to pass a function to the function that creates the array. The function that i need to pass is one to be used with the OnClick event of the labels . I'm trying

void __fastcall MyForm::CreateArray(/*parameters*/,void __fastcall MyLabelOnClick(TObject* Sender)
{

for(int i = 0;i<64;i++)
{
/*code goes here*/
lblArray->OnClick = MyLabelOnClick;
}
}

but it's not working . Can anybody help me ?

Thanks in advance

Thor
 
Try this:
Code:
void __fastcall MyForm::CreateArray(TNotifyEvent *MyLabelOnClick)
{
   ...
}
If the event is not TNotifyEvent (ie it has params other than TObject* Sender) you will need to use the correct type instead of TNotifyEvent, eg. TMyComponentCustomEvent. To see what to use, just press F1 while the event has focus in the Object Inspector and look at the property declaratioon, it will look something like this:

__property TNotifyEvent OnClick = {read=FOnClick, write=FOnClick};
(you would use TNotifyEvent)

or

__property TTVEditedEvent OnEdited = {read=FOnEdited, write=FOnEdited};
(you would use TTVEditedEvent) [Thanks in advance|Hope I helped you]
Exodus300
World-Wide Alliance of Evil and Twisted People
[red]&quot;Experimentation by Example is the best learning tool&quot; - Exodus300[/red]
[pc3]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top