I understand the concept of pointers and how to use, but I just want to clear up a bit of confusion in my head about assigning a pointer to a record sub-element already pointed to by another pointer...
I've seen some questions elsewhere that are I think asking the same thing, but the answers are in C...
If I have:
type
TDetails = record
Name : string;
Origin : string;
end;
TMsgData = record
ID : string;
Code : integer;
Details : TDetails;
end;
var
MessageData = array of TMsgData;
I can obviously get a pointer to specific record of TMsgData type by:
var
pMessageData = ^TMsgData;
begin
pMessageData := @MessageData[0];
...
And of course I can then access all the record elements using that pointer with standard dereferencing.
But, how do I get a new pointer to just the Details record of MessageData[0] using the first pointer? I want to avoid having a pointer to a pointer so if pMessageData is free'd I still have the other pointer.
If I do
name := pMessageData.Details.Name;
then Delphi will automatically dereference this to give me the value of name. So if I did:
var
pMessageDetails = ^TDetails;
begin
pMessageDetails = @pMessageData.Details;
*or*
pMessageDetails = Addr(pMessageData^.Details);
Do either of those give me a pointer to a pointer or a new pointer to the original record?