c++ - how to write a function Click() for dynamic created button? -
Trying to write a simple VCL program for educating purposes (dynamically form, control etc.) ). There is such a sample code:
click __fastcall TForm1 :: button 1 (torque * sender) {TForm * formQuiz = new TForm (this); FormQuiz-> BorderIcons = TBorderIcons () & lt; & Lt; By System Menu & gt; & Gt; BiMinimize & gt; & Gt; BiMaximize; FormQuiz- & gt; Position = TPosition :: poDesktopCenter; FormQuiz- & gt; Width = 250; FormQuiz- & gt; Height = 250; FormQuiz- & gt; Visible = true; Teeton * BTNDAK.Tobin = New Tibetan (Form Conservancy); BtnDecToBin- & gt; Mother = form quasue; BtnDecToBin- & gt; Left = 88; BtnDecToBin- & gt; Top = 28; BtnDecToBin- & gt; Caption = "Dec to bin"; BtnDecToBin- & gt; Visible = true; }
I wonder how I can write a function for a dynamic button, so it will be called when the button is clicked. In this example I click 'btnDecToBin-> ();' Funk but I do not know where I should put it.
Insert ' zero __fastcall TForm1 :: button 1 (torque * sender) {}
'?
I appreciate any input, some keywords for Google
You can do two things, you can either create an action and add it to the button You can create such a function:
Zero __fastcall TForm1 :: DynButtonClick (TObject * Sender) / / Find out which button was pressed: TBITTON * BTN = Dynamic_Cast & Lt; Teabton * & gt; (Sender); If (BTN)}}
you set the OnClick property btnDecToBin-> OnClick = DynButtonClick
Binding along, please note that the function is within Form 1. This will work due to the closing nature (compiler specific additional) if you delete the context of click event before form1
before the form code the problem occurs in many ways it is in this In case there may be a more clean solution for using any action.
Edit: On another way to do this, if you have a standard layout for your quiz, you can use a TForm
from a custom TQuizForm
can be the successor of the class. In this manner you will not have to force the incident every time you form a form.
Comments
Post a Comment