TStringList vs. TList

前端 未结 8 1894
野性不改
野性不改 2021-02-05 02:31

what is the difference in using a standard

type 
  sl: TStringList 

compared to using a generic TList

type 
  sl: TList

        
8条回答
  •  庸人自扰
    2021-02-05 02:56

    TStringList has been around a long time in Delphi before generics were around. Therefore, it has built up a handful of useful features that a generic list of strings would not have.

    The generics version is just creating a new type that is identical to TList that works on the type of String. (.Add(), .Insert(), .Remove(), .Clear(), etc.)

    TStringList has the basic TList type methods and other methods custom to working with strings, such as .SaveToFile() and .LoadFromFile()

    If you want backwards compatibility, then TStringList is definitely the way to go.
    If you want enhanced functionality for working with a list of Strings, then TStringList is the way to go. If you have some basic coding fundamentals that you want to work with a list of any type, then perhaps you need to look away from TStringList.

提交回复
热议问题