深入类中的方法[2] - 关于覆盖与重定义

//标准的覆盖是这样的
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}

 

posted @ 2013-10-19 11:53  Wishmeluck  阅读(196)  评论(0编辑  收藏  举报