gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 14:44:03 25 4
gpt4 key购买 nike

我编写了一个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

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

最佳答案

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

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

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)

关于delphi - 为什么从 TCustomFrame 继承的组件看起来与 TFrame 不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40586128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com