Board index » delphi » Dynamically created TLabel doesn't show up

Dynamically created TLabel doesn't show up

I am sure this is very simple, but I need to create TLabels dynamically,
but when I do they don't appear on my form. Could somebody help?

var
  Label1: TLabel;
begin
  Label1 := TLabel.Create(Form1);
  Label1.Caption := 'Hello';
end;

This gets me nothing even though in debugging all of the properties seem
to be fine that I have checked. What am I missing?

Mitchell Blue

 

Re:Dynamically created TLabel doesn't show up


Mitchell,
   You have to specify a PARENT for the label, otherwise it will not show..
try this:

                   var mylabel:Tlabel;
                            begin
                               mylabel:=Tlabel.create(self);
                                       with mylabel do
                                       begin
                                              parent:=myform;
                                              left:=100;/// this could be
anything, of course..
                                              top:=500;
                                              caption:='Hello World!!';
                                         end;
                           end;

Good Luck!!

Dave
http://www.erols.com/dparsons

Quote
Mitchell Blue wrote in message <353D85B7.5930B...@harding.edu>...
>I am sure this is very simple, but I need to create TLabels dynamically,
>but when I do they don't appear on my form. Could somebody help?

>var
>  Label1: TLabel;
>begin
>  Label1 := TLabel.Create(Form1);
>  Label1.Caption := 'Hello';
>end;

>This gets me nothing even though in debugging all of the properties seem
>to be fine that I have checked. What am I missing?

>Mitchell Blue

Re:Dynamically created TLabel doesn't show up


I guess you forgot a line:

Label1 := TLabel.Create(Form1);
Label1.Parent := Form1;
Label1.Caption := 'Hello';

See help for TLabel.Parent.

Ralf.
--
guent...@cindatec.tcc-chemnitz.spam.de (please remove 'spam')

Mitchell Blue schrieb in Nachricht <353D85B7.5930B...@harding.edu>...

Quote
>I am sure this is very simple, but I need to create TLabels dynamically,
>but when I do they don't appear on my form. Could somebody help?

>var
>  Label1: TLabel;
>begin
>  Label1 := TLabel.Create(Form1);
>  Label1.Caption := 'Hello';
>end;

>This gets me nothing even though in debugging all of the properties seem
>to be fine that I have checked. What am I missing?

>Mitchell Blue

Re:Dynamically created TLabel doesn't show up


Quote
Mitchell Blue wrote:

> I am sure this is very simple, but I need to create TLabels dynamically,
> but when I do they don't appear on my form. Could somebody help?

Apart from anything else (such as size, location etc.), when you
dynamically create a control, you need to specify its parent.

Andrew
--
Andrew Gabb
 email: ag...@tpgi.com.au
 phone: +61 8 8342-1021
   fax: +61 8 8269-3280
Technology Australasia's website is at http://www.taa.com.au
-----

Re:Dynamically created TLabel doesn't show up


Hi,

don't forget to set the parent property to something.

label1 := TLabel.Create(Form1);
label1.Parent := Form1;
Label1.Caption := 'Hello';

good luck,
Martijn

--
Martijn Tonies
http://surf.to/seal97

<none of the text written above has got anything to do with Euro Partners
Informatici BV>

System Development
Euro Partners Informatici BV
http://www.euro-partners.nl

Mitchell Blue <mtb...@harding.edu> wrote in article
<353D85B7.5930B...@harding.edu>...

Quote
> I am sure this is very simple, but I need to create TLabels dynamically,
> but when I do they don't appear on my form. Could somebody help?

> var
>   Label1: TLabel;
> begin
>   Label1 := TLabel.Create(Form1);
>   Label1.Caption := 'Hello';
> end;

> This gets me nothing even though in debugging all of the properties seem
> to be fine that I have checked. What am I missing?

> Mitchell Blue

Re:Dynamically created TLabel doesn't show up


Change the code to the following:

var
  Label1: TLabel;
begin
  Label1 := TLabel.Create(Form1);
  Label1.Parent := Form1;            // <- newline
  Label1.Caption := 'Hello';
end;

You forgot to set the parent!!!

--

Janus N. T?ndering
Email: janusnt<alpha>usa<dot>net
Please correct my email address if you
want to mail me....thanks

Quote
Mitchell Blue wrote in message <353D85B7.5930B...@harding.edu>...
>I am sure this is very simple, but I need to create TLabels dynamically,
>but when I do they don't appear on my form. Could somebody help?

>var
>  Label1: TLabel;
>begin
>  Label1 := TLabel.Create(Form1);
>  Label1.Caption := 'Hello';
>end;

>This gets me nothing even though in debugging all of the properties seem
>to be fine that I have checked. What am I missing?

>Mitchell Blue

Other Threads