BelowCodeFrom http://blog.csdn.net/hellogv/, please note the source for reference!
I will not talk much about it. I will start with the focus of this article.
//---------------------------------------------------------------------------
Void _ fastcall tform1: button1click (tobject * sender)
{
// ---------- The first step is to dynamically create a window.
Tform * newform = new tform (application); // here tform is used to create a blank window
// ---------- Dynamically create controls
Tbutton * BTN = new tbutton (newform); // a button control is dynamically created here.
BTN-> caption = "mybutton"; // The name is "mybutton"
BTN-> parent = newform; // specifies the display in the dynamically created window
BTN-> onclick = myevent; // The onclick event is mapped to myevent. Note: The onclick and myevent parameters must be the same.
BTN-> show ();
Newform-> show ();
}
//---------------------------------------------------------------------------
Void _ fastcall tform1: myevent (tobject * sender)
{
Showmessage ("My events have been called ");
}