Download Now

    Reference TList<TItem>

    Declared in Codebot.Collections.pas on line 53

    TList<TItem> is a generic growable list of items
      TList<TItem> = class(TObject)
      public
        type
        { The type of items held by the list }
        ItemType = TItem;
        { A pointer to an item }
        PItemType = ^TItem;
        { The function used to compare items when sorting or searching }
        TListCompare = TCompare<TItem>;
        { Get the enumerator for the list }
        function GetEnumerator: IEnumerator<ItemType>;
      protected
        FItems: TArrayList<ItemType>;
        { Allows list types to take action on add }
        procedure AddItem(constref Item: ItemType); virtual;
        { Allows list types to take action on delete }
        procedure DeleteItem(var Item: ItemType); virtual;
        { If require delete is true delete item will be called for every item on
          clear }
        function RequiresDelete: Boolean; virtual;
        { Search the list for an equal item }
        function Find(Comparer: TListCompare; const Item: ItemType): Integer;
        { Request room for at least a minimum number of items }
        procedure Grow(MinCapacity: Integer);
      public
        { Clear the list and destroy it }
        destructor Destroy; override;
        { Add an item to the end of the list }
        procedure Add(const Item: ItemType);
        { Delete an item by index from the list }
        procedure Delete(Index: Integer);
        { Move item at old index to new index }
        procedure Move(OldIndex, NewIndex: Integer);
        { Exchange positions of two items in the list }
        procedure Exchange(A, B: Integer);
        { Remove all items from the list setting capacity and count to zero }
        procedure Clear;
        { Reclaim unused capacity }
        procedure Compact;
        { Sort the list }
        procedure Sort(Compare: TListCompare = nil); virtual;
        { A reference to the first item in the list }
        property Head: PItemType read GetHead;
        { The first item in the list }
        property First: ItemType read GetFirst;
        { The last item in the list }
        property Last: ItemType read GetLast;
        { Number of items in the list }
        property Count: Integer read FCount;
        { Allocated space in terms of number of items }
        property Capacity: Integer read GetCapacity write SetCapacity;
        { Get or set an item in the list Remarks When setting the existing item will
          be deleted }
        property Item[Index: Integer]: ItemType read GetItem write SetItem; default;
        { Retrieve a direct reference to the item }
        property Direct[Index: Integer]: PItemType read GetDirect;
      end;

    See also

    TArrayList<T> in Codebot.System.pas
    TCompare<T> in Codebot.System.pas