Runtime created objects

For N:=0 to Form1.ComponentCount-1 do
   Begin
      ListBox1.Items.Add(Form1.Components[N].Name);
   End;


simple enough it lists all the controls in listbox, but, if you create an object for example Button: Tbutton; .... Button:=TButton.Create(...); Button.Left.... and so on set the parenthandle, and then make it visible, loop through all the components on the form, and the user created component does not show up...

is that a bug or is that what it's supposed to do?
LVL 4
tobjectpascalAsked:
Who is Participating?
 
RickJCommented:
You need to give it a name.

B.Name := 'Whatever' ;

Rick.
0
 
kretzschmarCommented:
what do you give as owner?
usual the runtime-created component is added to the owners componentlist,
if you use nil as owner, well then ....
0
 
tobjectpascalAuthor Commented:
if it's a new project, and i do Tbutton.Create(Form); it still does not appear on the list..


Var
 B: TButton;
begin
 B:=TButton.Create(Form1);
 B.ParentWindow:=Form1.Handle;
 B.Top:=1;
 B.Left:=1;
 B.Width:=100;
 B.Height:=100;
 B.Visible:=True;
 B.Caption:='Press Me';
End;


procedure TForm1.Button1Click(Sender: TObject);
Var
 N: Integer;
begin
For N:=0 to Form1.ComponentCount-1 do
   Begin
      ListBox1.Items.Add(Form1.Components[N].Name);
   End;
end;


I must be missing something then, B.Owner can not be modified so what do you mean?
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
RickJCommented:
It would have been appearing in your list as blank.

Rick.
0
 
tobjectpascalAuthor Commented:
ahhhh what an idiot i am lol.... thanks
0
 
kretzschmarCommented:
*lol*
good point, RickJ

:-))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.