Limitations of the TList Class
The biggest problem with the TList class arises when you want to write software that is portable between Delphi 1.0 and Delphi 2.0. In Delphi 2.0, there are no limits on the number of items a list can hold, but in Delphi 1.0, a list is limited to at most 16,380 items. This limitation is due to restrictions imposed by the 16-bit memory architecture of Delphi 1.0: a TList object can hold only 64 kilobytes (KB) of memory. Since each item in the list is a Pointer, which occupies 4 bytes, this limits the total number of items that a TList can hold to about 16K. The actual limit is 16380 items. If you need to store more than 16380 items in a list, then you need to write your own class that manages multiple memory segments, which you will undertake in the next section, A Better TList Class.
When you want to write software that works the same in Delphi 1.0 and Delphi 2.0, the size restriction is a major stumbling block. Another limit is the difficulty in deriving new list classes from TList. This problem lies in the nature of how TList was written, with static methods instead of virtual methods. The lack of virtual methods makes it harder to use a derived class. You encounter this problem in both versions of Delphi.
A related problem is that TList defines a default array property that returns a Pointer value. Remember that a default array property lets you refer to a property without referring to the property name. This is very convenient when accessing a list item with the expression List[N] instead of the more cumbersome List.Items[N]. This restriction means you cannot derive a class from TList with a different default property, thereby making it more difficult to use derived classes.
In the next section, you will see how to write a class that eliminates these restrictions.
Copyright © 1996 Waite Group Press