Link to home
Start Free TrialLog in
Avatar of tobjectpascal
tobjectpascal

asked on

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?
Avatar of kretzschmar
kretzschmar
Flag of Germany image

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 ....
Avatar of tobjectpascal
tobjectpascal

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of RickJ
RickJ

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It would have been appearing in your list as blank.

Rick.
ahhhh what an idiot i am lol.... thanks
*lol*
good point, RickJ

:-))