AFAIK we cannot assign directly values to record members if the said record is in a generic structure.
For example, having:
type
TMyRec = record
Width: integer;
Height: integer;
end;
var
myList: TList<TMyRec>;
...
myList[888].Width:=1000; //ERROR here: Left side cannot be assigned.
...
Till now, I used a temporary variable in order to overcome this:
var
...
temp: TMyRec;
...
begin
...
temp:=myList[999];
temp.Width:=1000;
myList[999]:=temp;
...
end;
Ugly, slow, but works. But now I want to add to TMyRec
a dynamic array:
type
TMyRec = record
Width: integer;
Height: integer;
Points: array or TPoint;
end;
...or any other data structure which can became big so copying back and forth in a temporary variable isn't a feasible option.
The question is: How to change a member of a record when this record is in a generic structure without needing to copy it in a temporary var?
TIA for your feedback
A dynamic array variable is just a reference to the array. It's stored in the record as a single pointer. So you can continue with your current approach without any excessive copying. Copying an element to a temporary variable only copies a reference to the array and does not copy the array's contents. And even better, if you are assigning to the array's items then you don't need the copy at all. You can write:
myList[666].Points[0] := ...
If you do have a record that really is big then you would be better using a class rather than a record. Because an instance of a class is a reference, the same argument as above applies. For this approach you may prefer TObjectList<> to TList<>. The advantage of TObjectList<> is that you can set the OwnsObjects property to True and let the list be in charge of destroying its members.
You could then write
var
myList: TObjectList<TMyClass>
....
myList[666].SomeProp := NewValue;