在 C# 中,我可以通过以下方式访问基类base
关键字,在java中我可以通过以下方式访问它super
关键词。在delphi中如何做到这一点?
假设我有以下代码:
type
TForm3 = class(TForm)
private
procedure _setCaption(Value:String);
public
property Caption:string write _setCaption; //adding override here gives error
end;
implementation
procedure TForm3._setCaption(Value: String);
begin
Self.Caption := Value; //it gives stack overflow
end;
您收到了 stackoverflow 异常,因为该行
Self.Caption := Value;
是递归的。
您可以访问父属性Caption铸造Self
属性到基类,如下所示:
procedure TForm3._setCaption(const Value: string);
begin
TForm(Self).Caption := Value;
end;
或使用inherited
keyword
procedure TForm3._setCaption(const Value: string);
begin
inherited Caption := Value;
end;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)