如何使用C++ Builder在运行时以编程方式构造组件?

use*_*809 4 components runtime c++builder

非常基本的C++ Builder问题.我想在运行时创建一个TButton.我原以为下面的代码会这样做,但我看到表单上没有按钮:

__fastcall TForm2::TForm2(TComponent* Owner): TForm(Owner)  
{  
    TButton* b = new TButton(this);  
    b->Height = 100;  
    b->Width = 100;  
    b->Left = 0;   
    b->Top = 0;   
    b->Caption = "Testing";  
    b->Visible = true;  
    b->Enabled = true;  
}  
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助!

Ken*_*ite 6

你需要设置按钮 Parent(它显示的表面):

b->Parent = this;
Run Code Online (Sandbox Code Playgroud)