PPointer Pointer这两者有什么区别。
我已知:
PPointer是指向指针类型的指针
Polinter是无类型指针。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在Tobject类的classtype里有这样一段话
function TObject.ClassType: TClass;
begin
Pointer(Result) := PPointer(Self)^;
end;
该怎么理解呢?delphi为什么会有PPointer这样的类型,它的出现到底是处于什么样的目的?
我已知:
PPointer是指向指针类型的指针
Polinter是无类型指针。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在Tobject类的classtype里有这样一段话
function TObject.ClassType: TClass;
begin
Pointer(Result) := PPointer(Self)^;
end;
该怎么理解呢?delphi为什么会有PPointer这样的类型,它的出现到底是处于什么样的目的?
procedure TForm1.Button12Click(Sender: TObject);
begin
showmessage('PPointer(self) address:'+inttostr(integer(PPointer(self)))
+#13#10+'Pointer(self) address:'+inttostr(integer(Pointer(self)))
+#13#10+'PPointer(self)^ address:'+inttostr(integer(PPointer(self)^))
);
end;
根据上面的测试
PPointer(self) address 和 Pointer(self) address是一样的。
PPointer(self)^ address和上面的的地址值是不一样的。
所以我认为。self是指向对象的,PPointer(self)^ 是指向类的,一个是对象指针,一个是类指针。
不知道我理解的对不对。
var
a,b,c,d: Integer;
begin
a := Integer(Self);
b := integer(PPointer(self));
c := integer(Pointer(self));
d := integer(PPointer(self)^)
end;调试时的CPU WIndow:Unit1.pas.31: a := Integer(Self);//a,b,c的值都一样,都是[ebp-$04],即Self的地址
004552BC 8B45FC mov eax,[ebp-$04]
004552BF 8945F8 mov [ebp-$08],eax
Unit1.pas.32: b := integer(PPointer(self));
004552C2 8B45FC mov eax,[ebp-$04]
004552C5 8945F4 mov [ebp-$0c],eax
Unit1.pas.33: c := integer(Pointer(self));
004552C8 8B45FC mov eax,[ebp-$04]
004552CB 8945F0 mov [ebp-$10],eaxUnit1.pas.34: d := integer(PPointer(self)^)
004552CE 8B45FC mov eax,[ebp-$04]//先取Self的地址
004552D1 8B00 mov eax,[eax]//再取Self指向的内容的头4个字节,实际上就是VMT的地址
004552D3 8945EC mov [ebp-$14],eax所以1L更准确的说法是:Self指向的内容的头4个字节是VMT的地址。