为什么编译器会给我这个错误:'GetItem'的声明与之前的声明不同?

时间:2012-07-11 13:59:43

标签: delphi override

这是给我错误的代码:

TAdvSmoothDockItems = class(TCollection)
private
  FOwner: TAdvSmoothDock;
  FOnChange: TNotifyEvent;
protected
  function GetItem(Index: Integer): TAdvSmoothDockItem; virtual; //YLM_TMS_01
  procedure SetItem(Index: Integer; const Value: TAdvSmoothDockItem); virtual; //YLM_TMS_01
  function GetOwner: TPersistent; override;
public
  constructor Create(AOwner: TAdvSmoothDock); overload; virtual;    //YLM_TMS_01
  function Add: TAdvSmoothDockItem; virtual;    //YLM_TMS_01
  function Insert(Index: Integer): TAdvSmoothDockItem; virtual;    //YLM_TMS_01
  property Items[Index: Integer]: TAdvSmoothDockItem read GetItem write SetItem; default;
  procedure Delete(Index: Integer); virtual;    //YLM_TMS_01
published
  property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;


TKHAdvSmoothDockItems = class(TAdvSmoothDockItems)
  private
    FOwner: TKHAdvSmoothDock;
    FOnChange: TNotifyEvent;
  protected
    function GetItem(Index: Integer): TKHAdvSmoothDockItem; override;
    procedure SetItem(Index: Integer; const Value: TKHAdvSmoothDockItem); override;
    function GetOwner: TPersistent; override;
  public
    constructor Create(AOwner: TKHAdvSmoothDock);
    function Add: TKHAdvSmoothDockItem;
    function Insert(Index: Integer): TKHAdvSmoothDockItem;
    property Items[Index: Integer]: TKHAdvSmoothDockItem read GetItem write SetItem; default;
    procedure Delete(Index: Integer); override;
  published
    property OnChange: TNotifyEvent read FOnChange write FOnChange;
  end;

此代码给出了以下错误:

E2037'GetItem'声明与之前的声明不同

为什么?我已经将基类中的GetItem声明为“Virtual”,然后我尝试在下一个类中覆盖它(TKHAdvSmoothDockItems)......?如何解决?

1 个答案:

答案 0 :(得分:4)

由于

function GetItem(Index: Integer): TAdvSmoothDockItem; virtual;

不同
function GetItem(Index: Integer): TKHAdvSmoothDockItem; override;

结果类型必须相同。