Delphi:TIntList
TIntList is a very easy class to create. We take advantage of the fact that the Delphi TList object is designed to store 32 bit pointers and cheat it into storing 32 bit integers instead - after all, internally the two are exactly identical. TIntList has two properties
- IntCount: Integer - The number of integers in the list.
- Integers[Index: Integer] :Integer - The array of integer values stored in the list. This is the default property.
The principal methods of TIntList are listed below
- constructor CreateEx - This is the object constructor. Internally, it creates an instance of TList used to store integer values after typecasting them to a pointer.
- procedure ReadFromStream( AStream: TStream ) - Reads in integer values previously streamed out to memory or file.
- procedure WriteToStream( AStream: TStream ) - Writes integer values to memory or file.
- function Add( Value: Integer ) :Integer - Add the specified integer value to the list. Returns the number of entries in the list after addition.
- procedure ClearEx( ACount: Integer ) - Empties the list and prepares it to accept ACount new entries.
- function Decrement( Index: Integer ) :Boolean - Decrements the integer stored at Index by unity. Returns True if the post decrement value is zero. Raises an EListError exception if Index is invalid.
- procedure Delete( Index: Integer ) - Deletes the entry at Index. Does nothing if Index is invalid.
- function Discard( Value: Integer ) :Boolean - Finds and discards the first entry for Value in the list. Returns False if Value does not exist.
- function Find( Value: Integer ) :Integer - Finds the first occurrence of Value in the list and returns its index. Returns -1 if the list does not contain Value.
- procedure Increment( Index: Integer ) - Increments the value at Index by unity. Does nothing if Index is invalid.
- procedure Replicate( AList: TIntList ) - Discards the current list contents and replaces them with a copy of those in AList.
Usage:
Create an instance of TIntList whenever you need to store a sequence of related integers. Use TIntList methods and properties to manage your entries. Remember to free the instance once you are done.
Download