详细阐述这个问题的最好方法是举例说明我正在尝试做什么......
我定义了一个"基类":
TMyBaseClass = class(TPersistent)
protected
procedure Foo(const AValue: String); virtual;
// more methods here (many more in fact)
end;
Run Code Online (Sandbox Code Playgroud)
我现在定义一个后代类:
TMyDescendantClass = class(TMyBaseClass)
public
procedure Foo(const AValue: String); override;
// etc. for all desired methods I wish to elevate into Public
end;
Run Code Online (Sandbox Code Playgroud)
这里的问题是我必须重新定义TMyDescendantClass的方法"Foo"以将链调用传递给TMyBaseClass:
procedure TMyDescendantClass.Foo(const AValue: String);
begin
inherited;
end;
Run Code Online (Sandbox Code Playgroud)
这是浪费空间!我想知道是否有人知道任何方式来否定重新实现该方法的需要并且"继承".
一个理想的解决方案看起来像:
TMyDescendantClass = class(TMyBaseClass)
public
procedure Foo(const AValue: String); elevated;
// etc. for all desired methods
end;
Run Code Online (Sandbox Code Playgroud)
显然这是假设的,我知道Delphi语言中不存在关键字"已提升".是否有一个关键字具有相同的效果,我只是不知道?
谢谢!
没有这样的关键字.您可以通过使用新的可见性级别重新声明属性来轻松更改属性的可见性.但是没有类似的方法.
| 归档时间: |
|
| 查看次数: |
1836 次 |
| 最近记录: |