Solved

Run-time Label creation

Posted on 1998-10-01
5
201 Views
Last Modified: 2010-05-18
I am creating Label during run-time, but it doesn't appears on Form.
Where is the mistake?

procedure TForm1.Button1Click(Sender: TObject);
begin
     Label1 := TLabel.Create(Form1);
     Label1.Caption := '12345';
     Label1.Left := 50;
     Label1.Top := 30;
     Label1.Width := 50;
     Label1.Height := 20;
     Label1.Enabled := True;
     Label1. Visible := True;
end;
0
Comment
Question by:bor061297
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
efortier earned 50 total points
ID: 1341436
you have to tell the label on which "object" it will appear. if you want it on the main form, write:

Label1.parent:=Form1;

if you want the label on a panel or something else, just assign it to the Parent property.

I suggest you assign the PARENT property just after the you created the label (or any other object). Some objects will only set their properties if their parent is also set.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1341437
procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1 := TLabel.Create(self);
  eith Label1 do begin
    Parent := Form1;
    Caption := '12345';
    Left := 50;
    Top := 30;
    Width := 50;
    Height := 20;
    Enabled := True;
    Visible := True;
  end;
end;

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1341438
eith = with
0
 

Expert Comment

by:lgc5800
ID: 1341439
Hi here is an example :

var label1 : tlabel;
begin
    label1 := tlabel.create(self);
    label1.left := 50;
    label1.top := 50;
    label1.parent := self;
    label1.visible := true;
end;
0
 

Expert Comment

by:lgc5800
ID: 1341440
Hi here is an example :

var label1 : tlabel;
begin
    label1 := tlabel.create(self);
    label1.left := 50;
    label1.top := 50;
    label1.parent := self;
    label1.visible := true;
end;
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now