Delphi Programming

Using Delphi to Create Components Dynamically

2,919pages on
this wiki
Add New Page
Talk0 Share

To create a label component on the fly, create a new project with one form. On that form place a button and double-click on it to edit the click event handler. Write the following code:

 procedure TForm1.Button1Click(Sender: TObject);
   aLabel: TLabel;
   aLabel := TLabel.Create(self);
   aLabel.Parent := self;
   aLabel.Visible := True;
   aLabel.Caption := 'Created dynamically!';
   aLabel.Top := 10;
   aLabel.Left := 10;

Run the application and click on the button and you'll see the label created on the fly. You can even put instances of components in an array and manage them in a similar way to VBs Control Arrays.

See also:Edit

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.