what is the difference in using a standard
type sl: TStringList
compared to using a generic TList
type sl: TList<string>
?
As far as I can see, both behave exactly the same.
Is it just another way of doing the same thing?
Are there situations where one would be better than the other?
Thanks!
TStringList can hold up to 134,217,728 strings (MaxListSize+1).
TStringList maintains a list of strings. Use a string list object to store and manipulate a list of strings. TStringList implements the abstract properties and methods introduced by TStrings, and introduces new properties, events, and methods to: Sort the strings in the list. Prohibit duplicate strings in sorted lists.
TStringList can contain up to 2,147,483,647 strings. This is because the list is indexed using an integer. See String Types (Delphi) for information about the size limit of each string.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With