• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

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?
0
tobjectpascal
Asked:
tobjectpascal
  • 2
  • 2
  • 2
1 Solution
 
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
 
RickJCommented:
You need to give it a name.

B.Name := 'Whatever' ;

Rick.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now