Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically construct components at runtime using C++ Builder?

Very basic C++ Builder question. I want to create a TButton at runtime. I would have thought that the following code would do it, but I see no button on the form:

__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;  
}  

Thanks for any help!

like image 923
user1643809 Avatar asked Mar 15 '13 20:03

user1643809


1 Answers

You need to set the button's Parent (the surface it displays on):

b->Parent = this;
like image 189
Ken White Avatar answered Nov 14 '22 03:11

Ken White