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;
如果一个方法声明指定的方法标识符与继承得到的方法具有相同的名称但未包括指示字override,那么新的声明只是隐藏(hides)了继承得到的方法而没有覆盖它。在后裔类中,这两个方法都是存在的,这里的方法名称其范围是静态的。例如:
type
T1 = class(TObject)
procedure Act; virtual;
end;
T2 = class(T1)
procedure Act; //Act被再声明,但没有被覆盖(overridden)
end;
var
SomeObject: T1;
begin
SomeObject := T2.Create;
SomeObject.Act; //调用T1.Act
end;