我创建了一个类
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'要在不损失应用程序功能的情况下消除此警告,需要做些什么?
发布于 2012-12-19 22:39:34
使用reintroduce保留字来指示您要有意隐藏类中基类构造函数的编译器:
TMyClass = class (TComponent)
public
constructor Create(AOwner: TComponent; MyParam: Integer; Other: Boolean); reintroduce;这样,就不会显示任何警告。
也就是说,您必须重新考虑隐藏TComponent.Create构造函数。这不是一个好主意,因为默认的TComponent.Constructor是由Delphi调用的,当在设计时添加到表单/数据模块时,它会在运行时创建组件实例。
TComponent使构造函数成为虚拟的,以允许您在该过程中执行自定义代码,但您必须坚持使用Create公司,只将所有者传递给您,并让流机制在创建完成后处理属性的存储值。
如果是这样,你的组件必须支持“未配置”,或者在这个通用构造函数中为它的属性设置默认值。
为了方便起见,您可以提供更多具有不同名称的构造函数,以允许您在运行时通过代码传递不同属性的值来创建实例。
发布于 2015-02-03 06:42:16
如果对构造函数使用不同的名称,它可能会更好,可读性也更好,例如
constructor FormInfo.CreateWithSize(AOwner: TComponent; leftvalue, topvalue, heightvalue, widthvalue: integer);https://stackoverflow.com/questions/13954582
复制相似问题