以下不完整例子為生成一個TMemo的派生類及動態地創建該VCL控件。
Class TMemoEx : public TMemo
{
.
.
}
extern TMemoEx memoex;
Class TForm1 : Class TForm
{
public:
TMemoEx *MemoEx;
.
.
}
void _fastcall TForm1::FormShow(TObject *Sender)
{
MemoEx=new TMemoEx(this);
MemoEx->Parent=this;
.
.
}
總之,遵循以下步驟即可:
類定義;
extern TMemoEx memoex;
TMemoEx *MemoEx;
MemoEx=new TMemoEx(this);
MemoEx->Parent=this;