2

Here is the code which gives me the error:

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;

this code gives me the following error :

E2037 Declaration of 'GetItem' differs from previous declaration

why ? I have declared the GetItem in base-class as "Virtual" then I tried to override it in the next class (TKHAdvSmoothDockItems)...? how to fix it?

user1512094
  • 611
  • 2
  • 10
  • 23
  • possible duplicate of [How to override an inherited property?](http://stackoverflow.com/questions/11432942/how-to-override-an-inherited-property) – RBA Jul 11 '12 at 14:17
  • I suppose you want to override property type. Take a look at this: http://docwiki.embarcadero.com/RADStudio/en/Properties#Property_Overrides_and_Redeclarations – Marcodor Jul 11 '12 at 14:21
  • Consider using `reintroduce`. See this: http://stackoverflow.com/questions/741735/what-is-the-meaning-of-the-reintroduce-and-override-directives-in-delphi – Jerry Gagnon Jul 11 '12 at 14:21
  • It's not the same issue, @Rba. This question asks for an explanation of an error message. The error message never even occurred in the previous question. This question stems from the other one, but they aren't the same. This is a follow-up question, but it can stand on its own as well. – Rob Kennedy Jul 11 '12 at 14:39
  • exactly @RBA..this is not the same question..here am asking for an explanation of the error message! – user1512094 Jul 11 '12 at 14:56

1 Answers1

4

Because

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

differs from

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

the Result types need to be the same.

iamjoosy
  • 3,299
  • 20
  • 30
  • but as you can see the result cannot be the same because the property (Items) type is TKHAdvSmoothDockItem. – user1512094 Jul 11 '12 at 14:05
  • 1
    @user1512094 not sure what you are trying to adchieve, but if you override a function or procedure the types, including result types must be exactly the same. – iamjoosy Jul 11 '12 at 14:11
  • sorry bs i was not aware about the multiple questions! do you have any paper to read the rules of stackoverflow.com so i can make sure that i'm not breaking the rules! – user1512094 Jul 11 '12 at 14:54
  • For general information read [FAQ](http://stackoverflow.com/faq). For asking the same questions, people here are quick to find duplicates and closes them. It's much better to edit your question and better describe your problem. – LU RD Jul 11 '12 at 17:14