【发布时间】:2012-12-19 14:32:01
【问题描述】:
我创建了一个类
FormInfo = class (TComponent)
private
FLeftValue : Integer;
FTopValue : Integer;
FHeightValue : Integer;
FWidthValue : Integer;
public
constructor Create(
AOwner : TComponent;
leftvalue : integer;
topvalue : integer;
heightvalue : integer;
widthvalue : integer);
protected
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
function GetChildOwner: TComponent; override;
//procedure SetParentComponent(Value : TComponent); override;
published
property LeftValue : Integer read FLeftValue write FLeftValue;
property TopValue : Integer read FTopValue write FTopValue;
property HeightValue : Integer read FHeightValue write FHeightValue;
property WidthValue : Integer read FWidthValue write FWidthValue;
end;
进一步用于表单序列化。 Create方法有如下实现
constructor FormInfo.Create(AOwner: TComponent; leftvalue, topvalue, heightvalue,
widthvalue: integer);
begin
inherited Create(AOwner);
FLeftValue := leftvalue;
FTopValue := topvalue;
FHeightValue := heightvalue;
FWidthValue := widthvalue;
end;
由于组装,我收到警告
[dcc32 Warning] SerialForms.pas(17): W1010 Method 'Create' hides virtual method of base type 'TComponent'
在不丢失应用程序功能的情况下消除此警告需要做什么?
【问题讨论】:
-
从 .dfm 文件创建表单时,它会调用
TComponent中引入的虚拟构造函数。当表单来自 .dfm 时,您的构造函数将永远不会被调用。如果您的构造函数创建了任何对象,那么您就会遇到问题。你的设计可能是错误的。 -
隐藏继承的
TComponent虚拟 ctor 是个坏主意,如果您想让其他 ctor 使用不同的名称,例如CreatePos。 -
@user 你现在问了很多问题。这很好。但也许你可以考虑投票选出好的答案。
-
BTW 你知道在最近的 Delphi 版本中,你可以对错误/警告/提示消息执行 Ctrl-F1 以获取更多信息吗?值得注意的是,这个错误的帮助给出了具体的原因和解决方案
标签: delphi build constructor warnings delphi-xe2