代码如下:
unit test;
interface
uses
windows,SysUtils;
type TDo = class
public
m_hFile:THandle;
public
function foo():DWORD;
end;
implementation
function TDo.foo() : DWORD;
begin
m_hFile := $ffff; // 错误在这里,访问类成员变量冲突
end;
end.
in mainfrm.pas :
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
dotest:TDo;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if (dotest.foo()=0) then // 这里访问冲突,好像是对象未被分配内存
begin
showmessage('d');
end;
end;
unit test;
interface
uses
windows,SysUtils;
type TDo = class
public
m_hFile:THandle;
public
function foo():DWORD;
end;
implementation
function TDo.foo() : DWORD;
begin
m_hFile := $ffff; // 错误在这里,访问类成员变量冲突
end;
end.
in mainfrm.pas :
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
dotest:TDo;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if (dotest.foo()=0) then // 这里访问冲突,好像是对象未被分配内存
begin
showmessage('d');
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货