-11 Vote

Delphi: Dynamically created Label remains invisible

Question by Guest | 2013-10-21 at 21:43

On the Internet, I found a tutorial allowing me creating labels dynamically at runtime. I have tried to use the code in one of my applications, but for whatever reason, I cannot see my Label on the Form.

By now, I am using the following code so far:

with TLabel.Create(self) do begin
  name:='label1';
  left:=8;
  right:=8;
  caption:='My Label';
  visible:=true;
end;

As you can see, I have especially set the property "Visible" to true, but also this does not make the Label appearing on my Form.

What am I doing wrong? Can anyone help me?

ReplyPositiveNegative
0Best Answer2 Votes

You forgot to specify the property "Parent" for your label.

Please try to add the following line to your code where Form1 is the Form on which the label should appear:

parent := Form1;

This property determines to which other control your label is assigned. If the property is empty, your label is floating somewhere in the vacuum.

If your label should appear on your Form, you need to set this as a parent. 
2013-10-22 at 12:03

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.