Hi all!
Again I'm having a stupid question
Generics.Collections offers a
TList for records with
TList.Items to access the values. However, I can't assign fields of the record this way:
program Project1;
uses SysUtils,Generics.Collections;
type TRec = record
a: integer;
end;
type TRecList = specialize TList<TRec>;
var List: TRecList;
r: TRec;
begin
List := TRecList.Create;
r.a := 1;
List.Add(r);
List.Items[0].a := -1; //<------ project1.lpr(17,16) Error: Argument cannot be assigned to
FreeAndNil(List);
end.
TObjectList works perfectly in such situation.
Moreover
List.Items[0].a += -1; works but doesn't change the value. That really makes me only to guess what's going on here
Yes, the "
items" definition is
property Items[Index: SizeInt]: T read GetItem write SetItem; default;So, it's relatively clear why it's read-only. The direct access to the items by
protected
FItems: array of T; is actually protected... Is there anything I can do here except for moving
FItems to
Public (i.e. editing the
Generics.Collections)?
------
or is there a way to raise
FItems up to
public without modifying external
Generics.Collections unit?