Hey delphi users,
I just discovered something odd. Check this out:
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. Is there a way to do that?Code: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 hope fpc is more consistent with these things.
Bookmarks