Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TMemo "No parent window" problem

Status
Not open for further replies.

damichab

Programmer
Aug 2, 2004
3
0
0
AU
Hi,

I have a normal TForm derived class (normal Builder stuff... a dfm, cpp and h files) that contains a TPanel suitably named 'Panel' and within its constructor I have the following lines of code:

Code:
   mem =new TMemo(Panel);
   mem->Parent=Panel;
   mem->Lines->Strings[0]="testing";

mem being a private class variable of type TMemo*. This works without any problems. Next I have a purpose made class derived from TPanel, called from previous said class passing the form (this) as the owner to the TPanel and within its contructor the lines:

Code:
MyClass::MyClass(TComponent* owner): TPanel(owner) 
{
   TMemo* mem =new TMemo((TPanel*) this);
   mem->Parent=(TPanel*) this;
   mem->Lines->Strings[0]="testing";
   delete mem;
...

}

Here, however, on the line mem->Lines->Strings[]... I get the error: ...EInvalidOperation with message 'Control '' has no Parent window'... and I just cannot work out why. If anyone can summerise an answer or indicate a link to a previous post with a similar problem, I would be most appreciative.

Thanks in advance,

David.


 
Hy. The problem is that the parent of the memo should be a TWinControl, but the Tpanel class is derived from TControl, so the parent is usually the Form where you want to show the memo. Change mem->parent = Form1(or the name of your form) and comment the line "delete mem" to see it work. Sorry it took so long. :)
 
Hi ctoma2005,

Thankyou for your response.

The answer, however, turned out to be that I was not setting the Parent's Parent (top level parent). I had tried assigning the parent to the form before posting this question but to no avail. In any case, TWinControl is an ancestor to both TForm and TPanel.

Regards,

David.
 
Ok. My bad. Maybe I didn't copy the exact code that you said, but i got the same error until I changed the parent to TForm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top