Solved

Run-time Label creation

Posted on 1998-10-01
5
224 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LAN or WAN ? 11 106
control image tags in a string ? 12 154
Moving (cutting/pasting) controls in a TTabbedNotebook... 7 48
DBCtrlGrid, Delphi, Scroll 8 60
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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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