我有一个非常基本和简单的类,如下所示:
装载机;
interface
uses
Vcl.Dialogs;
type
TLoader = Class(TObject)
published
constructor Create();
end;
implementation
{ TLoader }
constructor TLoader.Create;
begin
ShowMessage('ok');
end;
end.
Run Code Online (Sandbox Code Playgroud)
从Form1我称之为:
procedure TForm1.Button1Click(Sender: TObject);
var
the : TLoader;
begin
the := the.Create;
end;
Run Code Online (Sandbox Code Playgroud)
现在,在the := the.Create部件之后,delphi显示消息,'ok'然后给我一个错误并说Project Project1.exe raised exception class $C0000005 with message 'access violation at 0x0040559d: read of address 0xffffffe4'.
它也显示了这一行:
constructor TLoader.Create;
begin
ShowMessage('ok');
end; // <-------- THIS LINE IS MARKED AFTER THE ERROR.
Run Code Online (Sandbox Code Playgroud)
我是德尔福的新手.我正在使用Delphi XE2,我无法设法修复此错误.有没有人给我看路径或有解决方案?
And*_*and 16
var
the : TLoader;
begin
the := the.Create;
Run Code Online (Sandbox Code Playgroud)
是不正确的.它应该是
var
the : TLoader;
begin
the := TLoader.Create;
Run Code Online (Sandbox Code Playgroud)
你的语法错了.如果要构造新对象,则应在构造函数调用中使用类名,而不是变量名:
procedure TForm1.Button1Click(Sender: TObject);
var
the : TLoader;
begin
the := TLoader.Create;
end;
Run Code Online (Sandbox Code Playgroud)