Board index » cppbuilder » Error: Control has no parent window

Error: Control has no parent window

Hi,
where can I first access the Handle of a TCustomControl derived component?
I tried accessing it in my component constructor what results in "Control
has no parent window".

In the docs I found:
"Do not refer to the Handle property during component creation or streaming.
The underlying window does not exist until the first time the Handle
property is referenced. When this occurs, the HandleNeeded method is called
automatically."

So I moved my initialization code which needs the handle to
AfterConstruction() but I still get the same error?

thanks,
Nick

 

Re:Error: Control has no parent window


thanks for your reply,
I will search the archives on this topic.
Just one thing I noticed:
When the component is being dropped on the form at design-time Loaded()
seems not to be called. Actually there is nothing to load, or am I wrong?
Nick

Re:Error: Control has no parent window


Loaded is not used at design-time at all, only during runtime when streaming
in the design-time data.

Gambit

Quote
"nicolasr" <nicol...@gmx.net> wrote in message

news:3d740f9f@newsgroups.borland.com...
Quote
> When the component is being dropped on the form
> at design-time Loaded() seems not to be called. Actually
> there is nothing to load, or am I wrong?

Re:Error: Control has no parent window


Quote
nicolasr wrote:
> I will search the archives on this topic.

It might be hard to find.  Try this:
www.mers.com/merlist/borland/public/cppbuilder/vcl/components/writing...

Quote
> Just one thing I noticed:
> When the component is being dropped on the form at design-time Loaded()
> seems not to be called. Actually there is nothing to load, or am I wrong?

I don't know what type of initialization you need to perform, but you could
override CreateWnd(), however, it is called before properties are streamed-
in, if they are.  As a result, any properties in the .dfm which differ from their
default values would overwrite a setting made here.

Re:Error: Control has no parent window


thanks for your link

Quote
> I don't know what type of initialization you need to perform, but you
could
> override CreateWnd(), however, it is called before properties are
streamed-
> in, if they are.  As a result, any properties in the .dfm which differ
from their
> default values would overwrite a setting made here.

I want to create a Direct3D device which renders its scene onto the entire
component canvas. And the function that creates the device asks for the
target window handle. So there won't be many properties regarding the window
itself, probably only width and height.
I think CreateWnd() might be the right place.
thanks,
Nick

Re:Error: Control has no parent window


CreateWindowHandle() would probably be better than CreateWnd(), since
CreateWindowHandle() is the lowest level you can get where the window handle
is first available.  Also, use DestroyWindowHandle() so you can unhook your
D3D stuff whenever the window is destroyed.

Gambit

Quote
"nicolasr" <nicol...@gmx.net> wrote in message

news:3d75233d$1@newsgroups.borland.com...
Quote
> I want to create a Direct3D device which renders its
> scene onto the entire component canvas. And the
> function that creates the device asks for the target
> window handle. So there won't be many properties
> regarding the window itself, probably only width
> and height. I think CreateWnd() might be the right place.

Re:Error: Control has no parent window


Quote
> CreateWindowHandle() would probably be better than CreateWnd(), since
> CreateWindowHandle() is the lowest level you can get where the window
handle
> is first available.  Also, use DestroyWindowHandle() so you can unhook
your
> D3D stuff whenever the window is destroyed.

thanks for the pointer!
Nick

Other Threads