Board index » cppbuilder » Creating a custom component in another custom component

Creating a custom component in another custom component

Hi to All !

I've created two custom components :
- TMyPanel, inherited from TCustomPanel ;
- TMyLabel inherited from TCustomLabel.

I want to create a TMyLabel instance "from inside" TMyPanel ; for that, I've
declare in the .h file something like that :
protected :
                TMyLabel* ALabel ;

In the .cpp file, I've created ALabel in the TMyPanel's constructor with
this line :
ALabel = new TMyLabel(this) ;

In the destructor, I destruct ALabel like that :
delete ALabel ;

But, when in the IDE, I drop MyPanel, I do not "see" the MyLabel's instance.
Have I made a huge mistake ?

Thanks to You All !!!
Jean-Louis

 

Re:Creating a custom component in another custom component


"Jean-Louis Brabant" <jl.brab...@wanadoo.fr> schreef in bericht
news:3eb936ad@newsgroups.borland.com...

Quote
> Hi to All !
> Have I made a huge mistake ?

Yes, a very huge mistake. You didn't set the Parent from your label.
As a punishment you are not allowed to use BCB anymore, only VB.<G>

Peter

Re:Creating a custom component in another custom component


Quote
"Jean-Louis Brabant" <jl.brab...@wanadoo.fr> wrote in message

news:3eb936ad@newsgroups.borland.com...

Quote
> In the destructor, I destruct ALabel like that :
> delete ALabel ;

Technically, that is not really needed, since the Label has an Owner, so it
will be automatically freed for you.  Explicitally freeing the Label
yourself won't hurt anything, though.

Quote
> But, when in the IDE, I drop MyPanel, I do not "see"
> the MyLabel's instance.

You probably didn't set the Label's Parent property as well:

    ALabel->Parent = this;

Gambit

Other Threads