chronozphere
11-11-2010, 07:12 PM
Hey delphi users,
I just discovered something odd. Check this out:
type
PPPPMyRec = ^PPPMyRec;
PPPMyRec = ^PPMyRec;
PPMyRec = ^PMyRec;
PMyRec = ^TMyRec;
TMyRec = record
Str: String;
Int: Integer;
end;
procedure TForm1.Button5Click(Sender: TObject);
var
P: PMyRec;
PP: PPMyRec;
PPP: PPPMyRec;
PPPP: PPPPMyRec;
begin
New(P);
P^.Str := 'test';
P^.Int := 5;
PP := @P;
PPP := @PP;
PPPP := @PPP;
//A pointer to a record... only one dereference needed
ShowMessage(P^.Str);
//A pointer to a pointer to a record... STILL ONLY ONE DEREFERENCE NEEDED!!
ShowMessage(PP^.Str);
//triple pointer... now we need to add an extra dereference operator
ShowMessage((PPP^)^.Str);
//Yet another extra ^
ShowMessage(((PPPP^)^)^.Str);
Dispose(P);
end;
I think this is disturbing. In the second case, it's not possible to set the value of P by using PP^, because it dereferences 2 times at once. :o Is there a way to do that?
I hope fpc is more consistent with these things.
I just discovered something odd. Check this out:
type
PPPPMyRec = ^PPPMyRec;
PPPMyRec = ^PPMyRec;
PPMyRec = ^PMyRec;
PMyRec = ^TMyRec;
TMyRec = record
Str: String;
Int: Integer;
end;
procedure TForm1.Button5Click(Sender: TObject);
var
P: PMyRec;
PP: PPMyRec;
PPP: PPPMyRec;
PPPP: PPPPMyRec;
begin
New(P);
P^.Str := 'test';
P^.Int := 5;
PP := @P;
PPP := @PP;
PPPP := @PPP;
//A pointer to a record... only one dereference needed
ShowMessage(P^.Str);
//A pointer to a pointer to a record... STILL ONLY ONE DEREFERENCE NEEDED!!
ShowMessage(PP^.Str);
//triple pointer... now we need to add an extra dereference operator
ShowMessage((PPP^)^.Str);
//Yet another extra ^
ShowMessage(((PPPP^)^)^.Str);
Dispose(P);
end;
I think this is disturbing. In the second case, it's not possible to set the value of P by using PP^, because it dereferences 2 times at once. :o Is there a way to do that?
I hope fpc is more consistent with these things.