listCount

listCount(): Integer;

The listCount method of the ComboBox or ListBox class returns the current number of actual entries and entries that are yet to be read in the list portion of a list box or combo box control.

Use the listCount method to iterate through the entries in the list box or combo box, or to test whether there are any entries in the list box or combo box.

The code fragments in the following examples show the use of the listCount method.

app.msgBox("Done " & fromList.listCount.String, "" ,0);
if listBox1.listCount > 20 then
        listBox1.listObject := listBox1.itemObject[19];
    else
        listBox1.listObject := null;
endif;

The return value is adjusted when the displayEntry event method returns a null string (""), indicating that the entry does not appear in the list.

It is much more efficient to copy a GUI value into a local variable for reuse rather than request the value again. For example, listBox.listCount requires the calling of a list box method to retrieve the value. Storing the value in a local property for reuse avoids a significant overhead for the second and subsequent requests for that value when it will not change.

The first of the following examples is much more expensive than the second of these examples.

while count <= listBox.listCount do   // inefficient use of the method

vars
    listCount : Integer;
begin
    listCount := listBox.listCount;   // recommended use of the method
    while count <= listCount do
        ...
    endwhile;
end;

When the listCount method is used with the listCollection method, the value returned by the listCount method is the logical number of entries in the list box or combo box (that is, it returns a total of the number of entries for which the displayEntry event method has already returned a string and the number of entries in the collection that are yet to be accessed).

When the listCount method is used with the displayEntry event method, the returned value is only the number of entries loaded in the list box or the list portion of the combo box. It has no relationship to the size of the attached collection.