PTest = ^TTest;
TTest = class;
private
Procedure FuncOne;
Public
Constructor Create;
End;Procedure TTest.FuncOne
begin
ShowMessage(IntToStr(Integer(Self)));
ShowMessage(IntToStr(Integer(@Self)));
end;Constructor TTest.Create(...);
begin
inherited Create;
FuncOne;
end;
......
MyTest,MyTest2:TTest;
......
MyTest :=TTest.Create;
MyTest2:=TTest.Create;
ShowMessage(IntToStr(Integer(@MyTest)));
ShowMessage(IntToStr(Integer(@MyTest2)));
ShowMessage(IntToStr(Integer(MyTest)));
ShowMessage(IntToStr(Integer(MyTest2)));
该程序共显示了8次地址信息
我的理解:
@MyTest应该和调用MyTest.Create时的@Self相同
@MyTest2应该和调用MyTest2.Create时的@Self相同
MyTest应该和调用MyTest.Create时的Self相同
MyTest2应该和调用MyTest2.Create时的Self相同
结果是:MyTest在Create时的@Self和MyTest2在Create时的@Self相同,且MyTest在Create时的@Self和@MyTest不同,其他都是可以理解的,为什么会有这样的问题?该如何解决?
TTest = class;
private
Procedure FuncOne;
Public
Constructor Create;
End;Procedure TTest.FuncOne
begin
ShowMessage(IntToStr(Integer(Self)));
ShowMessage(IntToStr(Integer(@Self)));
end;Constructor TTest.Create(...);
begin
inherited Create;
FuncOne;
end;
......
MyTest,MyTest2:TTest;
......
MyTest :=TTest.Create;
MyTest2:=TTest.Create;
ShowMessage(IntToStr(Integer(@MyTest)));
ShowMessage(IntToStr(Integer(@MyTest2)));
ShowMessage(IntToStr(Integer(MyTest)));
ShowMessage(IntToStr(Integer(MyTest2)));
该程序共显示了8次地址信息
我的理解:
@MyTest应该和调用MyTest.Create时的@Self相同
@MyTest2应该和调用MyTest2.Create时的@Self相同
MyTest应该和调用MyTest.Create时的Self相同
MyTest2应该和调用MyTest2.Create时的Self相同
结果是:MyTest在Create时的@Self和MyTest2在Create时的@Self相同,且MyTest在Create时的@Self和@MyTest不同,其他都是可以理解的,为什么会有这样的问题?该如何解决?
var
P1,P2:Pointer;
....
P1:=@X;
P2:=@X;
虽然P1=P2,但是指针变量P1的地址和P2的地址却不等.也就是说@P1<>@P2
楼主该明白了吧