I have a method (Delphi 2009):
procedure TAnsiStringType.SetData(const Value: TBuffer; IsNull: boolean = False); begin if not IsNull then FValue:= PAnsiString(Value)^; inherited; end;
This is an abstract method in the base class, where "Value: Pointer" expects a pointer to the corresponding data, for example:
String = PString AnsiString = PAnsiString Integer = PInteger Boolean = PBoolean
So, I am trying to pass the value as follows:
var S: AnsiString; begin S:= 'New AnsiString Buffer'; SetBuffer(PAnsiString(S)); end;
But casting from AnsiString to PAnsiString does NOT work, I can understand why, but I want to know what the result of casting is. So I wrote a simple test:
var Buffer: AnsiString; P1: Pointer; P2: Pointer; P3: Pointer; P4: Pointer; begin P1:= PAnsiString(Buffer); P2:= Addr(Buffer); P3:= @Buffer; P4:= Pointer(Buffer); P5:= PChar(Buffer[1]); WriteLn('P1: ' + IntToStr(Integer(P1))); WriteLn('P2: ' + IntToStr(Integer(P2))); WriteLn('P3: ' + IntToStr(Integer(P3))); WriteLn('P4: ' + IntToStr(Integer(P4))); WriteLn('P5: ' + IntToStr(Integer(P5))); end;
Result:
P1: 5006500 P2: 1242488 P3: 1242488 P4: 5006500 P5: 67
Where:
- P2 and P3, is the address of Buffer: AnsiString - P5 is the Char Ord value of Buffer[1] char, in this case "67 = C" - How about P1 and P4?
What is the meaning of P1 and P4?
source share