将Frame祖先从TFrame改为TAppFrame后DFM异常的原因咨询
VCL Frame继承自定义基类后的IDE与运行时异常问题
我正在使用VCL和Frames开发多视图应用,计划根据应用状态在主窗体的客户区加载不同的Frame。主窗体已创建完成,中间预留区域用于放置Frame(设置Align属性为alClient实现自动填充),同时编写了基类TAppFrame,用于存放所有视图共有的构造函数和方法。
最初通过IDE创建TFrameMain = class(TFrame),首次加载完全正常,但修改其父类为自定义基类后出现异常:在设计完Frame后,我引入App.FrameUtils单元,将TFrameMain的父类改为TAppFrame,保存并关闭单元后再次打开时,DFM视图加载弹出错误提示:
Error reading frameMain.TabOrder: Property TabOrder does not exist. Ignore the error and continue? NOTE: Ignoring the error may cause components to be deleted or property values to be lost.
此时设计界面中Frame显示为带边框的窗体样式,运行程序时则报错:
Error reading frameMain.ClientHeight: Property ClientHeight does not exist.
奇怪的是,按照以下步骤操作后程序可以正常运行:
- 将
TFrameMain的父类改回TFrame - 保存并关闭单元标签
- 重新打开标签,此时会弹出TabOrder相关错误(此步骤必须执行)
- 将
TFrameMain的父类改回TAppFrame并保存,无论是否关闭单元,再次打开都会回到最初的错误状态 - 编译后应用可正常显示
TFrameMain类代码(第5步状态)
TframeMain = class(TAppFrame) scGPPanel1: TscGPPanel; btnDownloadMostRecent: TscGPGlyphButton; scGPPanel2: TscGPPanel; lblLastUpdate: TscGPLabel; lblCurrentVersion: TscGPLabel; lvVersions: TscAdvancedListBox; procedure btnDownloadMostRecentClick(Sender: TObject); private { Private declarations } FApplicationProgressBar: TscGPProgressBar; public { Public declarations } constructor Create(AOwner: TComponent; AProgressBar: TscGPProgressBar);// override; procedure UpdateScreenInfo();// override; end; implementation constructor TframeMain.Create(AOwner: TComponent; AProgressBar: TscGPProgressBar); begin FApplicationProgressBar := AProgressBar; inherited Create(AOwner); end;
TAppFrame类代码
TAppFrame = class(TFrame) public constructor Create(AOwner: TComponent); overload; // Just to get rid of the hiding warning. constructor Create(AOwner: TComponent; AProgressBar: TscGPProgressBar); overload; virtual; abstract; procedure UpdateScreenInfo(); virtual; abstract; end; implementation constructor TAppFrame.Create(AOwner: TComponent); begin inherited Create(AOwner); end;
我已经找到修改DFM文件继承关系的解决办法,但仍有两个疑问:
- 为何IDE仅移除DFM中找不到的属性,却不更新继承关系?
TAppFrame继承自TFrame且未修改任何访问修饰符,为何会找不到TabOrder、ClientHeight这类属性?
内容的提问来源于stack exchange,提问作者Arthur Araujo
相关产品推荐
相关产品推荐

