"Control has no parent window" message

General TRichView support forum. Please post your questions here
Post Reply
martindholmes
Posts: 131
Joined: Mon Aug 29, 2005 12:03 pm

"Control has no parent window" message

Post 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);
martindholmes
Posts: 131
Joined: Mon Aug 29, 2005 12:03 pm

Post 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
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Can you send me a simple project reproducing this problem?
martindholmes
Posts: 131
Joined: Mon Aug 29, 2005 12:03 pm

Post 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.
MLefebvre
Posts: 191
Joined: Mon Aug 29, 2005 4:28 pm
Location: France
Contact:

Post 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 ...
martindholmes
Posts: 131
Joined: Mon Aug 29, 2005 12:03 pm

Post 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
martindholmes
Posts: 131
Joined: Mon Aug 29, 2005 12:03 pm

Post 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
Post Reply