TStringList vs. TList

前端 未结 8 1877
野性不改
野性不改 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 03:04
    • TStringList is a descendant of TStrings.
    • TStringList knows how to sort itself alphabetically.
    • TStringList has an Objects property.
    • TStringList doesn't make your code incompatible with all previous versions of Delphi.
    • TStringList can be used as a published property. (A bug prevents generic classes from being published, for now.)
    0 讨论(0)
  • 2021-02-05 03:07

    TStringList has been used for far too long and has many advantages, all mentioned by Rob Kennedy.

    The only real disadvantage of using it as a pair of a string and an object is the necessity of casting object to the actual type expected and stored in this list (when reading) and as far as I know Embarcadero did not provide Delphi 2009 and up VCL libraries with generic version of TStringList.

    To overcome this limitation I implemented such list for internal use and for almost 3 years it serves it's purpose so I decided to share it today: https://github.com/t00/deltoo#tgenericstringlist

    One important note - it changes the default property from Strings to Objects as in most cases when object is stored in a list it is also the mostly accessed property of it.

    0 讨论(0)
提交回复
热议问题