Board index » cppbuilder » adding a component to a component

adding a component to a component

I would like to create a custom component TMyPanel
which should contain
a number of items like for instance a TButton, a TImage etc. and add the TMyPanel
component to the Component Palette.
The creation of a TMyPanel was successfull;
However I failed to make the OKButton visible in any way.
I tried for example to create an instance of TButton in the
constructor of the TMyPanel component by "new" etc.
but all attempts to visualise the Button failed.

Code used:

//---------------------------------------------------------------------------

#ifndef MyPanelH
#define MyPanelH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class PACKAGE TMyPanel : public TPanel
{
  private:
  protected:
  public:
    __fastcall TMyPanel(TComponent* Owner);
  __published:
    TButton* OKButton;

Quote
};

//---------------------------------------------------------------------------
#endif

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "MyPanel.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//

static inline void ValidCtrCheck(TMyPanel *)
{
  new TMyPanel(NULL);

Quote
}

//---------------------------------------------------------------------------
__fastcall TMyPanel::TMyPanel(TComponent* Owner)
  : TPanel(Owner)
{
  OKButton = new Tbutton(this);
Quote
}

//---------------------------------------------------------------------------
namespace Mypanel
{
  void __fastcall PACKAGE Register()
  {
    TComponentClass classes[1] = {__classid(TMyPanel)};
    RegisterComponents("Samples", classes, 0);
  }
Quote
}

//---------------------------------------------------------------------------

Any clues as to how to visualise the components on TMyPanel?

 

Re:adding a component to a component


You forgot to set the button's Parent property to be the panel.

    __fastcall TMyPanel::TMyPanel(TComponent* Owner)
        : TPanel(Owner)
    {
        OKButton = new Tbutton(this);
        OKButton->Parent = this;
    }

Gambit

Quote
"henk" <henk.vanno...@net.hcc.nl> wrote in message news:3d580689$1@dnews...
> However I failed to make the OKButton visible in any way.
> I tried for example to create an instance of TButton in the
> constructor of the TMyPanel component by "new" etc.
> but all attempts to visualise the Button failed.

Re:adding a component to a component


THANKS!!!
Misinterpreted Owner and Parent to be the same....

"Remy Lebeau [TeamB]" <gambi...@yahoo.com> wrote:

Quote
>You forgot to set the button's Parent property to be the panel.

>    __fastcall TMyPanel::TMyPanel(TComponent* Owner)
>        : TPanel(Owner)
>    {
>        OKButton = new Tbutton(this);
>        OKButton->Parent = this;
>    }

>Gambit

Re:adding a component to a component


Nope.  The Owner is strictly for memory management, whereas the Parent
control visibility and placement.

Gambit

Quote
"henk" <henk.vanno...@net.hcc.nl> wrote in message news:3d583072$1@dnews...

> THANKS!!!
> Misinterpreted Owner and Parent to be the same....

Other Threads