//标准的覆盖是这样的
TBass = class
procedure Proc; virtual; {或用 dynamic}
end;
TChild = class(TBass)
procedure Proc; override;
end;
//以下几种情况属于重定义, 其中例 3-5 还会有编译提示
{例1}
TBass = class
procedure Proc;
end;
TChild = class(TBass)
procedure Proc;
end;
{例2}
TBass = class
procedure Proc;
end;
TChild = class(TBass)
procedure Proc; virtual;
end;
{例3}
TBass = class
procedure Proc; virtual;
end;
TChild = class(TBass)
procedure Proc; virtual;
end;
{例4}
TBass = class
procedure Proc; virtual;
end;
TChild = class(TBass)
procedure Proc;
end;
{例5}
TBass = class
procedure Proc; virtual;
end;
TChild = class(TBass)
procedure Proc; dynamic;
end;
{上面这五种情况我们尽量不要使用}
//方法重定义时, 避免编译提示的办法
{办法1: 使用 reintroduce 指示字}
TBass = class
procedure Proc; virtual;
end;
TChild = class(TBass)
procedure Proc; reintroduce;
end;
{办法2: 使用编译器指令}
TBass = class
procedure Proc; virtual;
end;
{$WARNINGS OFF}
TChild = class(TBass)
procedure Proc; virtual;
end;
{$WARNINGS ON}
|
请发表评论