gpt4 book ai didi

delphi - 重写Create方法时,Delphi组件错误00000000

转载 作者:行者123 更新时间:2023-12-03 19:24:13 25 4
gpt4 key购买 nike

我在Delphi中创建了一个组件,并且试图覆盖create方法,如下所示:

unit DefButton;

interface

uses
Vcl.Dialogs,
Vcl.StdCtrls, Vcl.ExtCtrls,
System.SysUtils, System.Classes, Vcl.Controls, Vcl.Graphics, Vcl.Forms;

type
TDefButton = class(TPanel)
private
{ Private declarations }
protected
constructor Create(AOwner: TComponent); override;
public
{ Public declarations }
published
{ Published declarations }
end;

procedure Register;

implementation


constructor TDefButton.Create(AOwner: TComponent);
begin
ShowMessage('test!');
end;


procedure Register;
begin
RegisterComponents('Default Controls', [TDefButton]);
end;

end.


但是,当我运行它时,它显示消息“ test”,但随后抛出此消息:

enter image description here

然后它再次显示该消息,然后抛出该消息:

enter image description here

有什么想法吗?我尝试使用Google搜索,但找不到针对此特定情况的答案...

最佳答案

您需要在构造函数中调用inherited;,因此它将调用从祖先类到TObject构造函数的构造函数链。

试试这个:

constructor TDefButton.Create(AOwner: TComponent);
begin
inherited;
ShowMessage('test!');
end;

关于delphi - 重写Create方法时,Delphi组件错误00000000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56112281/

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