Pointer Lists 


The "IPointerList" stores simple pointers. For a full list of methods and properties look at the IPointerList Reference.

type IPointerList = interface (IList) ['{F6B8D485-40DB-11D3-A52D-00005A180D69}'];

When creating a new "PointerList", you can either create it emptily, or you can right away fill it with some items. You can also enter a "destroyProc". If you don't do that, you have to handle the deallocation of the pointer items yourself before you clear the list. If you enter a "destroyProc", this procedure gets called for each pointer item that is deleted from the list. This makes deallocation much easier for you.

function NewPointerList : IPointerList; overload;

type TDestroyPointerProc = procedure (var item: pointer);

function NewPointerList (const items: array of pointer;
                         destroyProc: TDestroyPointerProc = nil) : IPointerList; overload;

The "Items" property gives you read and write access to the items of the list:

property IPointerList.Items [index: integer] : pointer;

With the following property you can get and even directly set the size of the array which holds the items. That means when you set the array to a size which is smaller then IList.ItemCount you're deleting items from the list. Setting the "Capacity" to zero consequently deletes all items from the list.

property IPointerList.Capacity : integer;

Use the methods "AddItem(s)" to add one or more items to our list. The method "InsertItem" inserts the specified item at the specified position. This makes sense only for a non sorted list, of course. The result of all 3 methods is the new index of the (first) added item.

function IPointerList.AddItem    (item        : pointer         ) : integer;
function IPointerList.AddItems   (const items : array of pointer) : integer;

function IPointerList.InsertItem (item        : pointer;
                                  index       : integer = 0     ) : integer;

You can either delete an item from the list by giving in it's index or by giving in the item itself. With the method "Clear" you can delete all items at once.

function  IPointerList.DeleteItem (index : integer) : boolean; overload;
function  IPointerList.DeleteItem (item  : pointer) : boolean; overload;

procedure IPointerList.Clear;

The method "FindItem" returns the index of the "item". If it is not contained in this list, the result value is "-1".

function IPointerList.FindItem (item: pointer) : integer;

Some parts of the sorting functionality were already introduced with the properties IList.SortDown and IList.SortInfo. Here is the 3rd missing member, namely "SortProc", which wants to have a function that you have to define yourself. This "TComparePointer" function gets 2 items and must return which one should be placed before or after the other one. Additionally you can use the methods "GetSortParams" or "SetSortParams" to access all 3 sort properties at the same time.

type TComparePointer = function (const list: IList; item1, item2: pointer; info: integer) : integer;

property IPointerList.SortProc : TComparePointer;

function IPointerList.GetSortParams (var func: TComparePointer;
                                     var down: boolean;
                                     var info: integer        ) : boolean;
function IPointerList.SetSortParams (    func: TComparePointer;
                                         down: boolean = true;
                                         info: integer = 0    ) : boolean;

The following method simply swaps the position of two items in the list. This makes sense only for non sorted lists, or course.

function IPointerList.Swap (index1, index2: integer) : boolean;