Quick start manual
7-12
Delphi Language Guide
Methods
Overriding versus hiding
If a method declaration specifies the same method identifier and parameter signature
as an inherited method, but doesn’t include override, the new declaration merely
hides the inherited one without overriding it. Both methods exist in the descendant
class, where the method name is statically bound. For example,
type
T1 = class(TObject)
procedure Act; virtual;
end;
T2 = class(T1)
procedure Act; // Act is redeclared, but not overridden
end;
var
SomeObject: T1;
begin
SomeObject := T2.Create;
SomeObject.Act; // calls T1.Act
end;
Reintroduce
The reintroduce directive suppresses compiler warnings about hiding previously
declared virtual methods. For example,
procedure DoSomething; reintroduce; // the ancestor class also has a DoSomething method
Use reintroduce when you want to hide an inherited virtual method with a new one.
Abstract methods
An abstract method is a virtual or dynamic method that has no implementation in the
class where it is declared. Its implementation is deferred to a descendant class.
Abstract methods must be declared with the directive abstract after virtual or
dynamic. For example,
procedure DoSomething; virtual; abstract;
You can call an abstract method only in a class or instance of a class in which the
method has been overridden.
Overloading methods
A method can be redeclared using the overload directive. In this case, if the
redeclared method has a different parameter signature from its ancestor, it overloads
the inherited method without hiding it. Calling the method in a descendant class
activates whichever implementation matches the parameters in the call.