I have the 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 on the base class, where "Value: Pointer" expects the pointer of the corresponding data, as:
String = PString
AnsiString = PAnsiString
Integer = PInteger
Boolean = PBoolean
So I try to pass the value like this:
var
S: AnsiString;
begin
S:= 'New AnsiString Buffer';
SetBuffer(PAnsiString(S));
end;
But a cast from AnsiString to PAnsiString does NOT work, I can see why, but I want to know what the result of the 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;
The result is:
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?