You are using confusing terminology:
virtual -- a method that uses polymorphic calls
override -- a compiler keyword to identify replacing a virtual method
overload -- a means to use multiple methods with the same name, differing only in parameter signature
What occurs in TObjectList where Add() replaces the Add() method is TList is more accurately referred to as "hiding" the parent method. Even though you now have a different version in the child class, it is not polymorphic (the binding will be static based on the compile time class)
When hiding the parent method you can declare the new method virtual and further descendents will be polymorphic but the parent class does not become polymorphic.
Main Topics
Browse All Topics





by: knightmadPosted on 2005-09-30 at 05:55:38ID: 14991589
You can't override them if they are not virtual, only overload them. But there is no problem with it, even Borland overloads it, check what they done in the same unit (contnrs.pas) TObjectList is declared. It seems to be the only way to do it:
TComponentList = class(TObjectList)
private
FNexus: TComponent;
protected
procedure Notify(Ptr: Pointer; Action: TListNotification); override;
function GetItems(Index: Integer): TComponent;
procedure SetItems(Index: Integer; AComponent: TComponent);
procedure HandleFreeNotify(Sender: TObject; AComponent: TComponent);
public
destructor Destroy; override;
function Add(AComponent: TComponent): Integer;
function Extract(Item: TComponent): TComponent;
function Remove(AComponent: TComponent): Integer;
function IndexOf(AComponent: TComponent): Integer;
function First: TComponent;
function Last: TComponent;
procedure Insert(Index: Integer; AComponent: TComponent);
property Items[Index: Integer]: TComponent read GetItems write SetItems; default;
end;