Board index » delphi » Control has no parent window error

Control has no parent window error

I'am trying to access a group box which is contained inside a scroll
box.

I create the scrollbox as follows

myScrollBox := TScrollBox.Create(AOwner); { -- AOwner = to a TForm }
myScrollBox.Parent := AOwner;

myGroupBox := TGroupBox.Create(myScrollBox);
myGroupBox.Parent := myScrollBox;

when I try and do the following:

for Counter := 0 to AOwner.ComponentCount - 1 do
    if AOwner.Components[Counter] is TScrollBox then
      Parse(TScrollBox(AOwner.Components[Counter]) );

I receive the rror Control has no parent window on the call to PARSE.

Any help would be appreciated.

David
d...@acslink.aone.net.au

 

Re:Control has no parent window error


   I think you problem is with "AOwner" - unless that is the forms actual name.  
I suggest this:
  myScrollBox := TScrollBox.Create(TForm1);
  myScrollBox.Parent := TForm1;
...
  for Counter := 0 to ComponentCount - 1 do
    if Components[Counter] is TScrollBox then
      Parse(TScrollBox(Components[Counter]));

ComponentCount and Components will be the form's property, unless the for loop is in a
With statement - like  With myGroupBox Do.

You could use Self instead of TForm1, but then you would have to free myScrollBox before
you close the application or free the form.
--
                                                            Cleon.
                                                           <baile...@ionet.net>

David Lee <d...@acslink.aone.net.au> wrote in article
<33c8cab6.2802...@news.bne.aone.net.au>...

Quote
> I'am trying to access a group box which is contained inside a scroll
> box.

> I create the scrollbox as follows

> myScrollBox := TScrollBox.Create(AOwner); { -- AOwner = to a TForm }
> myScrollBox.Parent := AOwner;

> myGroupBox := TGroupBox.Create(myScrollBox);
> myGroupBox.Parent := myScrollBox;

> when I try and do the following:

> for Counter := 0 to AOwner.ComponentCount - 1 do
>     if AOwner.Components[Counter] is TScrollBox then
>       Parse(TScrollBox(AOwner.Components[Counter]) );

> I receive the rror Control has no parent window on the call to PARSE.

> Any help would be appreciated.

> David
> d...@acslink.aone.net.au

Other Threads