• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1900
  • 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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