Page 1 of 1
"Control has no parent window" message
Posted: Fri Sep 01, 2006 12:39 pm
by martindholmes
Hi folks,
I'm trying to create and use an offscreen TRichViewEdit and TRVStyle, within another class that isn't linked to a form. This is the initialization code:
FRVE := TRichViewEdit.Create(nil);
FRVE.Parent := TWinControl(Application.MainForm);
FRVS := TRVStyle.Create(nil);
Posted: Fri Sep 01, 2006 12:47 pm
by martindholmes
That message was incomplete for some reason, even though I typed it all!
I've also tried lots of other variations, using the Application.MainForm as owner as well as parent, and casting it or not casting it to TComponent (for owner) and TWinControl (for parent). In all cases, I get the dreaded "Control has no parent window" error.
Can anyone see what the problem might be, or suggest a solution?
All help appreciated,
Martin
Posted: Fri Sep 01, 2006 1:32 pm
by Sergey Tkachenko
Can you send me a simple project reproducing this problem?
Posted: Fri Sep 01, 2006 5:49 pm
by martindholmes
I'll put one together next week. I don't know if this is specific to RichView components or not, but it seems rather odd.
Posted: Fri Sep 01, 2006 6:13 pm
by MLefebvre
FYI : I think I have had a similar problem once, and solved it (without analysing that in depth, actually) by moving the RV setup code from the initialization section to some form startup event, where the form already exists. It seems that it is required by RV, when creating the RVE or maybe when assigning the RVStyle ...
Posted: Fri Sep 01, 2006 9:05 pm
by martindholmes
That could be it! I have a form which creates an object which, oncreate, creates another object which, oncreate, creates the RVE and the RVStyle. It's very possible that the main form hasn't finished being instantiated when its reference is being passed in to create the RVE and RVS.
I'll check that out. Thanks indeed for the suggestion; it hadn't occurred to me that the main form might not actually be there!
Cheers,
Martin
Posted: Tue Sep 05, 2006 12:02 pm
by martindholmes
That was it!
I was creating one of the objects during the Create event of the main form. At that point, the main form has presumably not finished being instantiated, and although no error was raised when the object was created, as soon as I tried to use it, the error appeared.
Many thanks indeed for your help.
Martin