SerialForms.pas(17):W1010方法“创建”隐藏基本类型“ TComponent”的虚拟方法 [英] SerialForms.pas(17): W1010 Method 'Create' hides virtual method of base type 'TComponent'

查看:269
本文介绍了SerialForms.pas(17):W1010方法“创建”隐藏基本类型“ TComponent”的虚拟方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个类

  FormInfo = class(TComponent)
private
FLeftValue:Integer;
FTopValue:整数;
FHeightValue:整数;
FWidthValue:整数;
public
构造函数Create(
AOwner:TComponent;
leftvalue:integer;
topvalue:integer;
heightvalue:integer;
widthvalue:整数);
受保护的
过程GetChildren(Proc:TGetChildProc; Root:TComponent);覆盖
函数GetChildOwner:TComponent;覆盖
//过程SetParentComponent(Value:TComponent);覆盖
已发布
属性LeftValue:整数读取FLeftValue写入FLeftValue;
属性TopValue:整数读取FTopValue写入FTopValue;
属性HeightValue:整数读取FHeightValue写入FHeightValue;
属性WidthValue:整数读取FWidthValue写入FWidthValue;
结尾;

进一步用于表单序列化。 Create方法具有以下实现

 构造函数FormInfo.Create(AOwner:TComponent; leftvalue,topvalue,heightvalue,
widthvalue:整数);
开始
继承Create(AOwner);

FLeftValue:=左值;
FTopValue:=最高价值;
FHeightValue:= heightvalue;
FWidthValue:= widthvalue;
结尾;

由于组装,我收到警告

  [dcc32警告] SerialForms.pas(17):W1010方法创建隐藏基本类型为 TComponent的虚拟方法

要在不失去应用程序功能的情况下摆脱此警告,必须做些什么?

解决方案

使用 reintroduce 保留字表示要有意在您的类中隐藏基类构造函数的编译器:

  TMyClass = class(TComponent)
public
构造函数Create(AOwner:TComponent; MyParam:Integer; Other:Boolean);重新介绍

这样,不会显示警告。



<就是说,您必须重新考虑隐藏TComponent.Create构造函数。这是一个坏主意,因为默认的TComponent.Constructor在设计时添加到表单/数据模块时,会在运行时由Delphi调用以创建您的组件实例。



TComponent使构造函数成为虚拟的,以允许您在该过程中执行自定义代码,但是您必须坚持只向所有者传递所有权的Create公司,并让流传输机制在完成创建后处理属性的存储值。 / p>

在这种情况下,您的组件必须支持未配置,或者在此 universal 构造函数中为其属性设置默认值。



您可以提供更多具有不同名称的构造函数,以允许您在运行时从代码中为不同属性传递值的实例来创建实例。


I created a class

  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;

which is used further for form serialization. The Create method has the following implementation

constructor FormInfo.Create(AOwner: TComponent; leftvalue, topvalue, heightvalue,
  widthvalue: integer);
begin
  inherited Create(AOwner);

  FLeftValue := leftvalue;
  FTopValue := topvalue;
  FHeightValue := heightvalue;
  FWidthValue := widthvalue;
end;

As a result of assembly I receive warning

[dcc32 Warning] SerialForms.pas(17): W1010 Method 'Create' hides virtual method of base type 'TComponent'

What it is necessary to make to get rid of this warning without loss of functionality of application?

解决方案

Use the reintroduce reserved word to indicate the compiler you want to intentionally hide the base class constructor in your class:

TMyClass = class (TComponent)
public
  constructor Create(AOwner: TComponent; MyParam: Integer; Other: Boolean); reintroduce;

That way, no warning is shown.

That said, you have to re-think hiding the TComponent.Create constructor. It is a bad idea since the default TComponent.Constructor is called by Delphi to create your component instances at run-time when added to forms/data modules at design time.

TComponent makes the constructor virtual to allow you execute custom code during that process, but you have to stick with the Create firm passing you only the owner, and let the streaming mechanism to deal with the stored values for properties after the creation is complete.

Your component have to support being "unconfigured" if that's the case, or setup default values for it's properties in this universal constructor.

You can provide more constructors, with different names, to allow you create instances at run-time from code passing values for the different properties for your convenience.

这篇关于SerialForms.pas(17):W1010方法“创建”隐藏基本类型“ TComponent”的虚拟方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆