详细说明这个问题的最佳方法是举一个我正在尝试做的事情的例子......
我定义一个“基类”:
TMyBaseClass = class(TPersistent)
protected
procedure Foo(const AValue: String); virtual;
// more methods here (many more in fact)
end;
我现在定义一个后代类:
TMyDescendantClass = class(TMyBaseClass)
public
procedure Foo(const AValue: String); override;
// etc. for all desired methods I wish to elevate into Public
end;
这里的问题是,我必须重新定义 TMyDescendantClass 的方法“Foo”,以将调用沿链传递到 TMyBaseClass:
procedure TMyDescendantClass.Foo(const AValue: String);
begin
inherited;
end;
这是浪费空间!我想知道是否有人知道有什么方法可以消除重新实现方法和 acl“继承”的需要。
理想的解决方案如下所示:
TMyDescendantClass = class(TMyBaseClass)
public
procedure Foo(const AValue: String); elevated;
// etc. for all desired methods
end;
显然这是假设的,我知道 Delphi 语言中不存在关键字“elevated”。是否有一个我不知道的具有相同效果的关键字?
Thanks!
没有这样的关键字。你可以平凡地通过使用新的可见性级别重新声明属性来更改属性的可见性 http://docwiki.embarcadero.com/RADStudio/en/Properties#Property_Overrides_and_Redeclarations。但对于方法来说,没有任何类似的东西。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)