Clear a TList or a TObjectList

后端 未结 5 1416
故里飘歌
故里飘歌 2021-02-19 05:33

I\'m a bit puzzled of what to use for storing objects in a list. Until now I have used TList and freed each item in a loop. Then I discovered TObjectList

5条回答
  •  一生所求
    2021-02-19 06:17

    If you are using a recent version of Delphi I suggest that you use a generic list.

    Right now you probably need to do a lot of casting when you use the objects from the list. With a generic list you don't have to do that anymore.

    For instance if you have:

    TMyObject = class(TObject);
    

    Then you make the list like this:

    TMyObjectList = TObjectList;
    

    There is an article in the Embarcadero Wiki:

    http://docwiki.embarcadero.com/CodeExamples/XE8/en/Generics_Collections_TObjectList_(Delphi)

提交回复
热议问题