Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1837
  • Last Modified:

"Control has no parent window" error message

Dear friends,

I'm developing a new component herited from a TreeView. I use a small application to test it since the very beginning without problem.
Today, when I drop the component from the palette to a new form, I got this message. Can you help me ?

Bob
0
baudewyns
Asked:
baudewyns
1 Solution
 
ahalyaCommented:
I think you can assign a parent in your control's create event;
e.g.
 
constructor TMyControl.Create(AOwner:TWinControl);

begin;
inherited Create;
Parent := AOwner;
....
0
 
aldynCommented:
Likely you trying to do some operations (painting or something else that requires control's window handle) before the parent is set. Delay it until the SetParent will be called.
0
 
toesableCommented:
make sure you have this statement: inherited Create(AOwner); in your constructor.  
0
Technology Partners: 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!

 
ITugayCommented:
Avoid drawing if Parent = nil.
0
 
alexstewart@betaCommented:
Sounds like this is happening at design time.

try checking componentstate for csDesigning and that parent<>nil before doing stuff.

You might try removing and reinstalling the package too, since it might be 'stale' code (designtime<>runtime).

I sometimes override the paint method, to tell me when its ok to do stuff, I wait for the first call to paint.

Alex

0
 
apostolostCommented:
Hi All,

You need to override the GetOwner Function.

Cheers,

  ApostolosT.
0
 
baudewynsAuthor Commented:
Well, the problem is not coming from my Tree component but from the Header created by code which is a recent addition. If I remove this part of the code, it's working fine.

I have to look around to fix the bug.
Many thanks to all of you.

I accept the answer to close the file even if not really relevant.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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