delphi,
If you want to "Copy" the "Contents" of the pointer to a record type, you could use
FRecords[I] := TSOME_RECORD(GetRecord(i)^
Here is my test case which shows that the contents of the pointer and the array are independent of each other:
Note: Record modified slightly for my convenience ;-)
PSOME_RECORD = ^TSOME_RECORD;
TSOME_RECORD = record
a:integer;
b:integer;
c:integer;
end;
procedure TForm1.Button2Click(Sender
Var
i: Integer;
MyPtr: PSOME_RECORD;
begin
For i := 1 to 10 do
begin
MyPtr := GetRecord(i);
RecAry[i] := TSOME_RECORD(MyPtr^);//cop
RecAry[i].a := RecAry[i].a * 10;//change array
//pointer contents remain unchanged:
Showmessage(Format('ary: %d, Ptr: %d',[RecAry[i].a, MyPtr^.a]));
end;
end;
function TForm1.GetRecord(i: integer): PSOME_RECORD;
begin
//create a new record for now
Result := AllocMem(Sizeof(TSOME_RECO
Result^.a := i;
result^.b := i*100;
result^.c := i*1000;
end;
Hope that helps.
...Shu
Main Topics
Browse All Topics





by: swift99Posted on 2003-11-03 at 23:04:52ID: 9676703
FRecord can be an array of PSomeRecord as easily as an array of Records
Then your code becomes
var
FRecords : array of PSOME_RECORD; <- this is the easy part ... :o)
begin
SetLength(FRecords, 10);
for i=0 to 9 do
FRecords[I] := GetRecord(i); <- this is the easy part ... :o)
end;