newIndex

newIndex(): Integer;

The newIndex method of the ComboBox or ListBox class returns the index of the item most recently added to a combo box or list box control, or the index of the item that most recently had its text changed by using either the itemText or text property if the value of the sorted property is true. Use the newIndex method with sorted lists when you need a list of values that correspond to each item in the itemObject or itemData property array. As you add an item in a sorted list, that item is inserted alphabetically in the list.

The newIndex method tells you where the item was inserted, so that you can set a corresponding value in the itemData or itemObject property array for the item at the same index. This value is also returned by the addItem method. The newIndex method returns -1 if there are no items in the list or if an item has been deleted since the last item was added.

When the text of an item is altered, the item may be repositioned in the list because of the sorted property. The new position of the item can be obtained by using the newIndex method, regardless of whether or not the entry shifted position.

The method in the following example shows the use of the newIndex method.

loadListBox() updating;
vars
    obj : Object;
begin
    app.mousePointer := self.MousePointer_HourGlass;
    if currentDict <> null then
        foreach obj in currentDict do
            listInstances.addItem(obj.display);
            listInstances.itemObject[listInstances.newIndex] := obj;
            if listInstances.newIndex.isEven then
                listInstances.itemBackColor[listInstances.newIndex] :=
                             LightYellow;
            endif;
        endforeach;
    endif;
    app.mousePointer := self.MousePointer_Arrow;
end;