Solved

Run-time Label creation

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

831 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