How can I update data in TList <T>?

I have this entry (structure):

type THexData = record Address : Cardinal; DataLen : Cardinal; Data : string; end; 

And I declared this list:

 HexDataList: TList<THexData>; 

I populated the list with some data. Now I would like to scan ListHexData and sometimes update the record item inside HexDataList.

Is it possible? How can i do

+1
source share
1 answer
 var Item: THexData; ... for i := 0 to HexDataList.Count-1 do begin Item := HexDataList[i]; //update Item HexDataList[i] := Item; end; 

The binding is that you want to change HexDataList[i] in place, but you cannot. When I work with TList<T> , which contains entries that I really subclass TList<T> , and replace the Items property with one that returns a pointer to the item, not a copy of the item. This allows you to change the place in place.

EDIT

Looking at my code again, I realize that I'm not really a subclass of TList<T> because it is too personal to retrieve pointers to the underlying data. This is probably a good solution. What I'm actually doing is implementing my own common class of classes, and this allows me to freely return pointers to records, if necessary.

+8
source

All Articles