如何阻止父类(super class)中的函数/过程在 Delphi (2007) 的子类中被覆盖?
我想标记它,这样它就不能被更改,我相信有一个final关键字,但我一生都找不到它的文档,所以我不能100%确定这就是我需要的。
最佳答案
如您所想,关键字是final
。请参阅http://dn.codegear.com/article/34324和http://blogs.teamb.com/rudyvelthuis/2005/05/13/4311 。您还可以将您的类标记为密封,以防止任何人继承它。您需要高于 7 的 Delphi 版本。
type
TSomeClass = class
protected
procedure SomeVirtualMethod; virtual;
end;
TOtherClass = class(TSomeClass)
protected
procedure SomeVirtualMethod; override; final;
end;
关于delphi - 在 Delphi 中阻止函数被覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/167247/