为什么从TCustomFrame继承的组件看起来与TFrame不同?

时间:2016-11-14 10:06:21

标签: delphi

我写了一个TCustomFrame的子类,它完全是从TFrame(Forms.pas单元)复制的:

  TMyFrame = class(TCustomFrame)
  private
    { Private declarations }
  public
    { Public declarations }
  published
    property Align;
    property Anchors;
    property AutoScroll;
    property AutoSize;
    property BiDiMode;
    property Constraints;
    property DockSite;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property Color nodefault;
    property Ctl3D;
    property Font;
    property Padding;
    property ParentBackground default True;
    property ParentBiDiMode;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;
    property OnAlignInsertBefore;
    property OnAlignPosition;
    property OnCanResize;
    property OnClick;
    property OnConstrainedResize;
    property OnContextPopup;
    property OnDblClick;
    property OnDockDrop;
    property OnDockOver;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnGetSiteInfo;
    property OnMouseActivate;
    property OnMouseDown;
    property OnMouseEnter;
    property OnMouseLeave;
    property OnMouseMove;
    property OnMouseUp;
    property OnMouseWheel;
    property OnMouseWheelDown;
    property OnMouseWheelUp;
    property OnResize;
    property OnStartDock;
    property OnStartDrag;
    property OnUnDock;
  end;

正如here所述,我最初定义了一个TFrame的子类,然后我切换到TCustomFrame并从DFM中删除了TabOrder属性为了能够在IDE中打开文件并重新编译包。

object MyFrame: TMyFrame
  Left = 0
  Top = 0
  Width = 296
  Height = 31
  TabOrder = 0 //this line has been deleted
end

enter image description here

一切似乎都没问题,但在打开并保存源文件后,DFM中有几个新属性,并出现标题栏:

object MyFrame: TMyFrame
  Left = 0
  Top = 0
  ClientHeight = 0
  ClientWidth = 280
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = True
  PixelsPerInch = 96
  TextHeight = 13
end

enter image description here

为什么会发生这种情况,我应该如何避免这些问题?

1 个答案:

答案 0 :(得分:6)

我相信你需要做的就是将你的帧类注册为自定义模块。

在你的包的注册程序中,添加如下内容:

procedure Register;
begin
[...]
  RegisterCustomModule(TMyFrame, TCustomMyFrameModule)
end;

TCustomMyFrameModule定义为

TCustomMyFrameModule = class(TCustomModule)
  function Nestable: Boolean; override;
end;

function TCustomMyFrameModule.Nestable: Boolean;
begin
  Result := True;
end;

编辑: 要使它工作,您需要为IDE中正在编辑的类的父类注册一个自定义模块。

TFrame1 = class(TMyFrame)
end;
RegisterCustomModule(TMyFrame, TCustomMyFrameModule)

如果要在IDE中编辑TMyFrame,则需要为TCustomFrame注册自定义模块。

TMyFrame = class(TCustomFrame)
end;
RegisterCustomModule(TCustomFrame, TCustomMyFrameModule)