How to set Button click event function, Borland Turbo c++?
I've created Button not with designer, but i don't know how to assign any 开发者_高级运维function for click event.
TButton *tl[15][15];
void __fastcall TForm1::MyButtonClick(TObject *Sender)
{
TButton *tlakt;
tlakt=(TButton*)Sender;
...
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
for (i=0;i<15;i++) for (j=0;j<15;j++){
tl [i][j]=new TButton(this);
tl [i][j]->Caption="";
tl [i][j]->Width=24;
tl [i][j]->Height=24;
tl [i][j]->TabStop=false;
tl [i][j]->Left=50+i*28;
tl [i][j]->Top=50+j*28;
tl [i][j]->Tag=i*100+j;
/* SET MyButtonClick as EVENT FUNCTION */
InsertControl (tl[i][j]);
}
}
Simply use this assignment for event handler: tl [i][j]->OnClick = MyButtonClick;
You can provide any class method (by name) as an event handler, which have the same signature as specified for certain event (in case of OnClick
it should be void __fastcall MethodName(TObject *Sender)
The easiest thing to do is just double click on the button and the IDE will create the method declarations for you. In your case, it looks like you copy/pasted one from somewhere and would like to assign it manually. You can do that in the object inspector. select the button in the designer, then click on the "events" tab in the object inspector. You can then assign any existing functions with the correct signature to the OnClick event.
精彩评论