How can I create Buttons at run-time?
Applies To: C++Builder 1 or higher
Category: Knowledge Base

-
- Start a new application.
-
- Double-click the OnCreate event of your form:
-
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- TButton *Buttons[5];
- for(int x = 0; x < 5; x++)< 5; x++)
- {
- Buttons[x] = new TButton(this);
- Buttons[x]->Parent = this;
- Buttons[x]->Left = 35;
- Buttons[x]->Width = 50;
- Buttons[x]->Height = 30;
- Buttons[x]->Top = (x + 1) * 35;
- Buttons[x]->Caption = IntToStr(x + 1);
- }
- }
-
- Freeing Components?
-
- - When one component owns another, the memory for the owned component is freed when its owner's memory is freed. This means that when the main form is destroyed, all Buttons on the form are also destroyed.
C++Builder Developer's Network
Copyright © Yoto Yotov