Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Run-time Label creation

Posted on 1998-10-01
5
Medium Priority
?
242 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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Screencast - Getting to Know the Pipeline
Suggested Courses

877 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