How to modify TList value?

前端 未结 4 743
醉酒成梦
醉酒成梦 2020-12-16 17:33

Delphi 2010 How to modify TList < record > value ?

type TTest = record a,b,c:Integer end;
var List:TList;
    A:TTest;
    P:Pointer;
....
..         


        
4条回答
  •  遥遥无期
    2020-12-16 17:33

    If you want to store records, dynamic arrays are more suited to handling them :

    type TTest = record a,b,c : Integer end;
    type TTestList = array of TTest;
    var List:TTestList;
        A:TTest;
        P:Pointer;
    ....
    ....
    
    SetLength( List, 20 );
    List[10]   := A; //<- OK
    List[10].a := 1; //<- Ok
    P := @List[10];  //<- Not advised (the next SetLength(List,xx) will blow the address away),
                     //   but technically works
    

    If you need to add methods to manipulate these data, you can store this array as the field of a class, and add your methods to this class.

提交回复
热议问题