Solved

Run-time Label creation

Posted on 1998-10-01
5
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

615 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