Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Delphi中停止已重写的函数_Delphi_Oop_Class - Fatal编程技术网

在Delphi中停止已重写的函数

在Delphi中停止已重写的函数,delphi,oop,class,Delphi,Oop,Class,在Delphi(2007)中,如何阻止超类中的函数/过程在子类中被重写 我想标记它,这样它就不能被修改,我相信有一个final关键字,但我一生都找不到它的文档,所以我不能100%确定这就是我需要的。关键字是final,正如你所想的那样。见和。您还可以将类标记为密封的,以防止任何人从中继承。您需要高于7的Delphi版本 type TSomeClass = class protected procedure SomeVirtualMethod; virtual; end;

在Delphi(2007)中,如何阻止超类中的函数/过程在子类中被重写


我想标记它,这样它就不能被修改,我相信有一个final关键字,但我一生都找不到它的文档,所以我不能100%确定这就是我需要的。

关键字是
final
,正如你所想的那样。见和。您还可以将类标记为密封的,以防止任何人从中继承。您需要高于7的Delphi版本

type
  TSomeClass = class
  protected
    procedure SomeVirtualMethod; virtual;
  end;

  TOtherClass = class(TSomeClass)
  protected
    procedure SomeVirtualMethod; override; final;
  end;
你说得对,这是“最后的”。这段代码显示了这一点。(摘自作者的一本书)

编辑提供:

[Pascal Error] Unit1.pas(11): E2352 Cannot override a final method
有一件事让我吃惊:Win32 Delphi支持此功能,而不仅仅是Delphi for.NET

[Pascal Error] Unit1.pas(11): E2352 Cannot override a final method