Skip to content

TList

Class to manage collections of pointers.

Declaration

Source position: classesh.inc line 585

type

  TList = class(TObject, IFPObserved)
  public
    constructor Create;
    destructor Destroy;
    procedure FPOAttachObserver;
    procedure FPODetachObserver;
    procedure FPONotifyObservers;
    procedure AddList;
    function Add : Integer;
    procedure Clear;
    procedure Delete;
    class procedure Error;
    procedure Exchange;
    function Expand : TList;
    function Extract : Pointer;
    function First : Pointer;
    function GetEnumerator : TListEnumerator;
    function Contains : Boolean;
    function IndexOf : Integer;
    procedure Insert;
    function Last : Pointer;
    procedure Move;
    procedure Assign;
    function Remove : Integer;
    procedure Pack;
    procedure Sort(Compare: TListSortCompare);
    procedure Sort(Compare: TListSortCompare; 
              SortingAlgorithm: PSortingAlgorithm);
    procedure Sort(Compare: TListSortComparer_Context; Context: Pointer);
    procedure Sort(Compare: TListSortComparer_Context; Context: Pointer; 
              SortingAlgorithm: PSortingAlgorithm);
    property Capacity: Integer; {rw}
    property Count: Integer; {rw}
    property Items[Index : Integer]: Pointer; {rw}
    property List: PPointerList; {r}
  end;

Inheritance

Implements: IFPObserved

Description

TList is a class that can be used to manage collections of pointers. It introduces methods and properties to store the pointers, search in the list of pointers, sort them. It manages its memory by itself, no intervention for that is needed. It has an event notification mechanism which allows to notify of list changes. This slows down some of TList mechanisms, and if no notification is used, TFPList may be used instead.

To manage collections of strings, it is better to use a TStrings descendant such as TStringList. To manage general objects, a TCollection class exists, from which a descendant can be made to manage collections of various kinds.

Properties

Member Visibility Description
Capacity public Current capacity (i.e. number of pointers that can be stored) of the list.
Count public Current number of pointers in the list.
Items public Provides access to the pointers in the list.
List read only public Memory array where pointers are stored.
See all Properties

Methods

Member Visibility Description
Add public Adds a new pointer to the list.
AddList public Add all pointers from another list.
Assign public Copy the contents of other lists.
Clear public Clears the pointer list.
Contains public
Create public Class to manage collections of pointers.
Delete public Removes a pointer from the list.
Destroy public Destroys the list and releases the memory used to store the list elements.
Error public Raises an EListError exception.
Exchange public Exchanges two pointers in the list.
Expand public Increases the capacity of the list if needed.
Extract public Remove the first occurrence of a pointer from the list.
First public Returns the first non-nil pointer in the list.
FPOAttachObserver public Add an observer to the list of observers.
FPODetachObserver public Remove an observer from the list of observers.
FPONotifyObservers public Notify observers of changes in the list.
GetEnumerator public Create an IEnumerator instance.
IndexOf public Returns the index of a given pointer.
Insert public Inserts a new pointer in the list at a given position.
Last public Returns the last non-nil pointer in the list.
Move public Moves a pointer from one position in the list to another.
Pack public Removes Nil pointers from the list and frees unused memory.
Remove public Removes a value from the list.
Sort public Sorts the pointers in the list.
See all Methods

See also

Name Description
TStrings Class to manage arrays or collections of strings.
TCollection Base class to manage collections of named objects.