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;
//---------------------------------------------------------------------------
#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);
//---------------------------------------------------------------------------
__fastcall TMyPanel::TMyPanel(TComponent* Owner)
: TPanel(Owner)
{
OKButton = new Tbutton(this);
//---------------------------------------------------------------------------
namespace Mypanel
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TMyPanel)};
RegisterComponents("Samples", classes, 0);
}
//---------------------------------------------------------------------------
Any clues as to how to visualise the components on TMyPanel?