Board index » delphi » dynamically creating an instance of a control

dynamically creating an instance of a control

I would like to create some of my labels and other standard VCL components at runtime, because they clutter the screen at design time. Here's my piece of code:

lblTitle := TLabel.Create(pnlContent);
lblTitle.Font.Size := 14;
lblTitle.Font.Style := [fsBold];
lblTitle.Caption := 'Welcome';

The component is not shown on the form. This code compiles and runs without errors, but the label is never drawn onto the screen. Why is this?

 

Re:dynamically creating an instance of a control


Quote
"Le Roux" <ler...@entelligence.co.za> wrote in message

news:3c975eb6$1_1@dnews...
Quote

> I would like to create some of my labels and other standard VCL

components at runtime, because they clutter the screen at design time.
Here's my piece of code:
Quote

> lblTitle := TLabel.Create(pnlContent);
> lblTitle.Font.Size := 14;
> lblTitle.Font.Style := [fsBold];
> lblTitle.Caption := 'Welcome';

> The component is not shown on the form. This code compiles and runs

without errors, but the label is never drawn onto the screen. Why is
this?

i think you have missed:

  lblTitle.Parent := pnlContent;

Re:dynamically creating an instance of a control


Thanks. I just new it would be a one liner.... :)

Quote
"Constantine Yannakopoulos" <k...@singular.gr> wrote:

>"Le Roux" <ler...@entelligence.co.za> wrote in message
>news:3c975eb6$1_1@dnews...

>> I would like to create some of my labels and other standard VCL
>components at runtime, because they clutter the screen at design time.
>Here's my piece of code:

>> lblTitle := TLabel.Create(pnlContent);
>> lblTitle.Font.Size := 14;
>> lblTitle.Font.Style := [fsBold];
>> lblTitle.Caption := 'Welcome';

>> The component is not shown on the form. This code compiles and runs
>without errors, but the label is never drawn onto the screen. Why is
>this?

>i think you have missed:

>  lblTitle.Parent := pnlContent;

Other Threads