Board index » delphi » How to make Dynamically created components visible?

How to make Dynamically created components visible?

Hi all,

I have a little problem...

I Want to make a CheckBox dynamically.
Easy enough, but nothing seems to show up on the form.
This is the code I used:

procedure TForm1.FormCreate(Sender: TObject);
var
Test : TComboBox;
begin
   Test:=TComboBox.Create(Form1); //(Sender as TComponent);
   Test.Visible:=True;
end;

Any Idea what goes wrong?  From sevral tests I did, I got confirmed that the
thing exists, but just is not visible!
Oh, and Top and Left are not an option too, tried it..

Greets,

Gert-Jan Rodenburg

 

Re:How to make Dynamically created components visible?


Try setting the Parent attribute of the Test combo box.

Ex:  Test.Parent := Form1;

Quote
G-J Rodenburg wrote:

> Hi all,

> I have a little problem...

> I Want to make a CheckBox dynamically.
> Easy enough, but nothing seems to show up on the form.
> This is the code I used:

> procedure TForm1.FormCreate(Sender: TObject);
> var
> Test : TComboBox;
> begin
>    Test:=TComboBox.Create(Form1); //(Sender as TComponent);
>    Test.Visible:=True;
> end;

> Any Idea what goes wrong?  From sevral tests I did, I got confirmed that the
> thing exists, but just is not visible!
> Oh, and Top and Left are not an option too, tried it..

> Greets,

> Gert-Jan Rodenburg

Re:How to make Dynamically created components visible?


Quote
G-J Rodenburg wrote:

> Hi all,

> I have a little problem...

> I Want to make a CheckBox dynamically.
> Easy enough, but nothing seems to show up on the form.
> This is the code I used:

> procedure TForm1.FormCreate(Sender: TObject);
> var
> Test : TComboBox;
> begin
>    Test:=TComboBox.Create(Form1); //(Sender as TComponent);
>    Test.Visible:=True;
> end;

> Any Idea what goes wrong?  

Yes, try this :
 procedure TForm1.FormCreate(Sender: TObject);
 var
 Test : TComboBox;
 begin
    Test:=TComboBox.Create(Form1); //(Sender as TComponent);
    Form1.InsertComponent(Test);
    Test.Visible:=True;
end;

You have to 'tell' the form it owns the component with InsertComponent.

Cheers
Beru

Re:How to make Dynamically created components visible?


Quote
G-J Rodenburg <g.rodenb...@student.utwente.nl> wrote:
> I Want to make a CheckBox dynamically.
> Easy enough, but nothing seems to show up on the form.

You need to set the parent property of the new control to the form.

Bye,
   Andy

--
----------------------------------------------------------------------------
Andreas H"orstemeier                       | ..Our continuing mission:
email: a...@scp.de                           | to seek out knowledge of C,
       a...@farpoint.westend.de            | to explore strange unix
www:   http://www.westend.de/~hoerstemeier | commands, and to boldly code
fido:  2:2452/108                          | where no one has man page 4.
----------------------------------------------------------------------------  

Re:How to make Dynamically created components visible?


In article <60thq5$...@dinkel.civ.utwente.nl>,

Quote
g.rodenb...@student.utwente.nl (G-J Rodenburg) writes:
>I have a little problem...

>I Want to make a CheckBox dynamically.
>Easy enough, but nothing seems to show up on the form.
>This is the code I used:

Differentiate between the Parent and the Owner of a component.

The Owner (a parameter of the OTObject.Create method) looks after the
disposal of the memory when the object is destroyed.

The Parent is the object from which the new object gets its windows
messages (including the message to make itself visible.

The Parent.InsertComponent(Child) adopts the child and sorts out parenting
settings.

Hope this helps

Alan Lloyd
alangll...@aol.com

Other Threads