Board index » cppbuilder » control " has no parent window

control " has no parent window

hi..

I'm creating a vertical TToolBar component.
when I want to paste it to a form. IDE said "control " has no parent
window"?
am I miss something?

(and any good sites about component writing?)

class PACKAGE TVToolBar : public TToolBar
{
......
__published:
        TImageList* _imgList;

Quote
};

__fastcall TVToolBar::TVToolBar(TComponent* Owner)
        : TToolBar(Owner)
{
    Images=_imgList; <---- error here, i guess
Quote
}

 

Re:control " has no parent window


When setting the Images property, internally it makes a call to the Parent
property, which hasn't been assigned yet in the constructor.

Override the inherited Loaded() method and do your assignment there instead.

Gambit

Quote
"none" <to...@ms41.url.com.tw> wrote in message news:3c631453$1_2@dnews...
> I'm creating a vertical TToolBar component.
> when I want to paste it to a form. IDE said "control " has no parent
> window"?
> am I miss something?

Re:control " has no parent window


something like....

void __fastcall TVToolBar::Loaded(void)
{
        Images=_imgList

Quote
}

???

it won't work

"Remy Lebeau" <gambi...@gte.net> ???g??l news:3c63208c$1_1@dnews...

Quote
> When setting the Images property, internally it makes a call to the Parent
> property, which hasn't been assigned yet in the constructor.

> Override the inherited Loaded() method and do your assignment there
instead.

Re:control " has no parent window


You need to call the base-class Loaded() first thing, that's important:

    void __fastcall TVToolBar::Loaded(void)
    {
        TToolBar::Loaded();
        Images=_imgList
    }

Also, you need to actually instantiate (and optionally fill if you need to)
the TImageList before you assign it.  You can do that in the constructor:

    __fastcall TVToolBar::TVToolBar(TComponent* Owner)
        : TToolBar(Owner)
    {
        _imgList = new TImageList(this);
    }

Gambit

Quote
"none" <to...@ms41.url.com.tw> wrote in message news:3c632e4f$1_1@dnews...
> void __fastcall TVToolBar::Loaded(void)
> {
>         Images=_imgList
> }
> ???

> it won't work

Re:control " has no parent window


thanks for your help.

but I must be stupid. still shows " control " has no parent window"

following is my code..

---------------.h---------------------------
class PACKAGE TVToolBar : public TToolBar
{
private:
        TImageList* _imgList;
protected:
        virtual void __fastcall Loaded(void);
public:
        __fastcall TVToolBar(TComponent* Owner);
__published:

Quote
};

---------.cpp-------
__fastcall TVToolBar::TVToolBar(TComponent* Owner)
        : TToolBar(Owner)
{
        _imgList=new TImageList(this);

Quote
}

void __fastcall TVToolBar::Loaded(void)
{

        TToolBar::Loaded();
        Images=_imgList;

Quote
}

"Remy Lebeau" <gambi...@gte.net> ???g??l news:3c634b07$1_1@dnews...
Quote
> You need to call the base-class Loaded() first thing, that's important:

>     void __fastcall TVToolBar::Loaded(void)
>     {
>         TToolBar::Loaded();
>         Images=_imgList
>     }

> Also, you need to actually instantiate (and optionally fill if you need
to)
> the TImageList before you assign it.  You can do that in the constructor:

>     __fastcall TVToolBar::TVToolBar(TComponent* Owner)
>         : TToolBar(Owner)
>     {
>         _imgList = new TImageList(this);
>     }

> Gambit

Re:control " has no parent window


append ..

__fastcall TVToolBar::TVToolBar(TComponent* Owner)
        : TToolBar(Owner)
{
        _imgList=new TImageList(this);
       Parent = (TWinControl*) Owner;

Quote
}

Re:control " has no parent window


If it is a design time component, BCB should automatically assign Parent.

Re:control " has no parent window


It's generally NOT a good idea to set the Parent in the constructor.  But if
you must, be aware that yo must make sure the Owner as actually a
TWinControl, or else you could run into problems during runtime when the
component attempts to access the Parent:

    __fastcall TVToolBar::TVToolBar(TComponent* Owner)
        : TToolBar(Owner)
    {
        Parent = dynamic_cast<TWinControl*>(Owner);
    }

Gambit

Quote
"Michael" <techon...@attbi.com> wrote in message news:3c643e37_2@dnews...
> append ..

> __fastcall TVToolBar::TVToolBar(TComponent* Owner)
>         : TToolBar(Owner)
> {
>         _imgList=new TImageList(this);
>        Parent = (TWinControl*) Owner;
> }

Re:control " has no parent window


The control would not emit the message if the control wasn't attempting to
paint on it's PARENT canvas. regardless of what SHOULD happen IYO.

Now NONE and I assume you tried the suggestion and it did not work.

--
Michael Harris

Quote
"robin" wrote in message

> If it is a design time component, BCB should automatically assign Parent.

Re:control " has no parent window


None. Does it solve your problem?

Quote

>    __fastcall TVToolBar::TVToolBar(TComponent* Owner)
>        : TToolBar(Owner)
>    {
>        Parent = dynamic_cast<TWinControl*>(Owner);
>    }

Other Threads