Interface Lists

The "IInterfaceList" can store any interface or COM object. So it can also store all my interfaces. However, if you need a list only for my interfaces, you should rather use the IBasicList, which will save you some type castings. For a full list of methods and properties look at the IInterfaceList Reference.

type IInterfaceList = interface (IList) ['{8C780300-4E4D-11D3-A52D-00005A180D69}'];

When creating a new "InterfaceList", you can either create it emptily, or you can right away fill it with some items:

function NewInterfaceList                                  : IInterfaceList; overload;
function NewInterfaceList (const items: array of IUnknown) : IInterfaceList; overload;

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

property IInterfaceList.Items [index: integer] : IUnknown;

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 IInterfaceList.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 IInterfaceList.AddItem    (const item : IUnknown         ) : integer;
function IInterfaceList.AddItems   (const items: array of IUnknown) : integer;

function IInterfaceList.InsertItem (const item : IUnknown;
                                    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  IInterfaceList.DeleteItem (      index : integer ) : boolean; overload;
function  IInterfaceList.DeleteItem (const item  : IUnknown) : boolean; overload;

procedure IInterfaceList.Clear;

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

function IInterfaceList.FindItem (const item: IUnknown) : 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 "TCompareInterface" 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 TCompareInterface = function (const list: IList; const item1, item2: IUnknown; info: integer) : integer;

property IInterfaceList.SortProc : TCompareInterface;

function IInterfaceList.GetSortParams (var func: TCompareInterface;
                                       var down: boolean;
                                       var info: integer          ) : boolean;
function IInterfaceList.SetSortParams (    func: TCompareInterface;
                                           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 IInterfaceList.Swap (index1, index2: integer) : boolean;