gpt4 book ai didi

Delphi:Create() 构造函数末尾出现访问冲突

转载 作者:行者123 更新时间:2023-12-03 14:49:36 27 4
gpt4 key购买 nike

我有一个非常基本且简单的类,如下所示:

单元装载机;

interface

uses
Vcl.Dialogs;

type
TLoader = Class(TObject)
published
constructor Create();
end;

implementation

{ TLoader }
constructor TLoader.Create;
begin
ShowMessage('ok');

end;

end.

在 Form1 中我这样调用它:

procedure TForm1.Button1Click(Sender: TObject);
var
the : TLoader;
begin
the := the.Create;
end;

现在,就在 the := the.Create 部分之后,delphi 显示带有 'ok' 的消息,然后给我一个错误并显示 Project Project1.exe 引发异常类 $C0000005,并显示消息“0x0040559d 处的访问冲突:读取地址 0xffffffe4”。

它还显示了这一行:

constructor TLoader.Create;
begin
ShowMessage('ok');

end; // <-------- THIS LINE IS MARKED AFTER THE ERROR.

我是德尔福的新人。我正在使用 Delphi XE2,但无法修复此错误。有人告诉我一条路径或有解决方案吗?

最佳答案

var
the : TLoader;
begin
the := the.Create;

不正确。应该是

var
the : TLoader;
begin
the := TLoader.Create;

关于Delphi:Create() 构造函数末尾出现访问冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12203457/

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