gpt4 book ai didi

delphi - 如何访问Delphi中的基(超)类?

转载 作者:行者123 更新时间:2023-12-03 14:39:32 25 4
gpt4 key购买 nike

在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;

最佳答案

您收到 stackoveflow 异常,因为该行

Self.Caption := Value;

是递归的。

您可以访问父属性 CaptionSelf 属性转换为基类,如下所示:

procedure TForm3._setCaption(const Value: string);
begin
TForm(Self).Caption := Value;
end;

或使用inherited关键字

procedure TForm3._setCaption(const Value: string);
begin
inherited Caption := Value;
end;

关于delphi - 如何访问Delphi中的基(超)类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12505695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com