我在 XE5 中创建了两个用户组件。第一个是 TCustomPanel 的后代,它的目的是成为第二个组件的容器,它是 TCustomLabel 的后代。
容器。
class PACKAGE TMenuPanel : public TCustomPanel
{
private:
protected:
public:
__fastcall TMenuPanel(TComponent* Owner);
__published:
__property Align;
__property Caption;
};
static inline void ValidCtrCheck(TMenuPanel *)
{
new TMenuPanel(NULL);
}
//---------------------------------------------------------------------------
__fastcall TMenuPanel::TMenuPanel(TComponent* Owner)
: TCustomPanel(Owner)
{
}
//---------------------------------------------------------------------------
namespace Menupanel
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TMenuPanel)};
RegisterComponents(L"Isis", classes, 0);
}
}
所包含的。
//---------------------------------------------------------------------------
class PACKAGE TMenuLabel : public TCustomLabel
{
private:
UnicodeString FOption;
int FIndex;
bool FHighlighted;
protected:
UnicodeString __fastcall GetOption();
void __fastcall SetOption(UnicodeString Option);
int __fastcall GetIndex();
void __fastcall SetIndex(int Index);
void __fastcall SetHighlighted(bool Flag);
void __fastcall RecaptionLabel();
public:
__fastcall TMenuLabel(TComponent* Owner);
__published:
__property int Index = {read=GetIndex, write=SetIndex, nodefault};
__property UnicodeString Option = {read=GetOption, write=SetOption, nodefault};
__property bool Highlighted = {read=FHighlighted, write=SetHighlighted, nodefault};
};
static inline void ValidCtrCheck(TMenuLabel *)
{
new TMenuLabel(NULL);
}
//---------------------------------------------------------------------------
__fastcall TMenuLabel::TMenuLabel(TComponent* Owner)
: TCustomLabel(Owner)
{
if (!Name.IsEmpty()) {
FOption = L"Option"+Name;
} else {
FOption = L"Option";
}
FHighlighted = false;
}
到目前为止一切顺利,组件已安装,它们出现在调色板中,它们的属性出现在检查器中。但...
如果MenuPanel 放在窗体上,MenuLabels 就放在里面。如果它放置在窗体中的面板上,则菜单标签将放置在面板中。有趣的是,如果将放置在表单中的 MenuPanel 剪切并粘贴到面板上,则 MenuLabels 位于 MenuPanel 中。
我知道这与设置 MenuPanel 的父属性有关,但构造函数采用 TComponent *Owner 参数,即 Form。然而,面板可以放置在面板内,面板内,标签将放置在右侧。
有没有人遇到过同样的问题?