Board index » cppbuilder » "Control '' has no parent window" error when deriving from TWinControl
Muzaffar Mahkamov
![]() CBuilder Developer |
Muzaffar Mahkamov
![]() CBuilder Developer |
"Control '' has no parent window" error when deriving from TWinControl2005-10-31 08:17:08 PM cppbuilder76 Hi, I'm deriving my class from TWinControl just to enable it to receive windows messages. class PACKAGE TMyClass : public TWinControl { public: __fastcall virtual TMyClass (TComponent* AOwner) : TWinControl(AOwner) { }; __fastcall TMyClass(HWND ParentWindow) : TWinControl(ParentWindow) {}; } and in my main form i create it: void __fastcall TForm1::btConnectClick(TObject *Sender) { myobj = new TMyClass(this); // an exception 'Control '' has not parent window' is thrown at the // line below. This is just a demonstration. ShowMessage( IntToStr( myobj->Handle ) ); } Did i forget to initialize something in the constructor? Thanks in advance Muzaffar |
Hans Galema
![]() CBuilder Developer |
2005-10-31 09:08:01 PM
Re:"Control '' has no parent window" error when deriving from TWinControl
Muzaffar Mahkamov wrote:
Quotevoid __fastcall TForm1::btConnectClick(TObject *Sender) QuoteDid i forget to initialize something in the constructor? |
Muzaffar Mahkamov
![]() CBuilder Developer |
2005-10-31 09:29:24 PM
Re:"Control '' has no parent window" error when deriving from TWinControl
Hans Galema wrote:
QuoteMuzaffar Mahkamov wrote: at 0x7c90eddc: write of address 0x00030ee0'. Process Stopped. Use Step or Run to continue. {smallsort} |
Hans Galema
![]() CBuilder Developer |
2005-10-31 09:59:21 PM
Re:"Control '' has no parent window" error when deriving from TWinControl
Muzaffar Mahkamov wrote:
Quote>myobj->Parent = this; QuoteProject E:\dev\test12\test.exe faulted with message: 'access violation Hans. |
Muzaffar Mahkamov
![]() CBuilder Developer |
2005-10-31 10:10:31 PM
Re:"Control '' has no parent window" error when deriving from TWinControl
Hans Galema wrote:
QuoteMuzaffar Mahkamov wrote: myobj = new TMyClass(this); myobj->Parent = this; // an AV occurs in the line below ShowMessage( IntToStr( myobj->Handle ) ); } Did the same thing in Delphi and it works fine even without assigning Parent manually. |
Hans Galema
![]() CBuilder Developer |
2005-11-01 12:35:40 AM
Re:"Control '' has no parent window" error when deriving from TWinControl
Muzaffar Mahkamov wrote:
Quote>Please show minimal code that demonstrates the AV problem. Hans. |
Muzaffar Mahkamov
![]() CBuilder Developer |
2005-11-01 03:04:31 AM
Re:"Control '' has no parent window" error when deriving from TWinControl
Hans Galema wrote:
QuoteMuzaffar Mahkamov wrote: |
Hans Galema
![]() CBuilder Developer |
2005-11-01 05:12:24 AM
Re:"Control '' has no parent window" error when deriving from TWinControl
Muzaffar Mahkamov wrote:
QuoteI've included the class declaration in my first post. The definitions of Hans. |
Muzaffar Mahkamov
![]() CBuilder Developer |
2005-11-01 01:56:49 PM
Re:"Control '' has no parent window" error when deriving from TWinControl
Hans Galema wrote:
QuoteMuzaffar Mahkamov wrote: causes the AV. Particularly, the call to myobj->Handle, which is not my code. Even if i do: int i = myob->Handle; the application crashes with AV. My configuration is: Borland C++ Builder 6 Enterprise, Update 4 |
Muzaffar Mahkamov
![]() CBuilder Developer |
2005-11-01 02:27:55 PM
Re:"Control '' has no parent window" error when deriving from TWinControl
Hans Galema wrote:
QuoteMuzaffar Mahkamov wrote: overflow. class PACKAGE TMyClass: public TWinControl { BEGIN_MESSAGE_MAP VCL_MESSAGE_HANDLER(WM_DEVICE_CONNECTED, TMessage, WMDEVICECONNECTED) VCL_MESSAGE_HANDLER(WM_DEVICE_DISCONNECTED, TMessage, WMDEVICEDISCONNECTED) END_MESSAGE_MAP(TMyClass) } changed it to: class PACKAGE TMyClass: public TWinControl { BEGIN_MESSAGE_MAP VCL_MESSAGE_HANDLER(WM_DEVICE_CONNECTED, TMessage, WMDEVICECONNECTED) VCL_MESSAGE_HANDLER(WM_DEVICE_DISCONNECTED, TMessage, WMDEVICEDISCONNECTED) END_MESSAGE_MAP(TWinControl) } and it works fine. Thanks for you help :) |
Hans Galema
![]() CBuilder Developer |
2005-11-01 05:18:48 PM
Re:"Control '' has no parent window" error when deriving from TWinControl
Muzaffar Mahkamov wrote:
QuoteFinally, i've found the problem. It was in the message handler. Sorry, class PACKAGE TMyClass : public TWinControl { public: __fastcall virtual TMyClass (TComponent* AOwner) : TWinControl(AOwner) { }; __fastcall TMyClass(HWND ParentWindow) : TWinControl(ParentWindow) {}; } was all there was. If you need help then please be more exact. Hans. |