Deleting Elements from a List

Call the ListDeleteString function to delete the current string from a list. Or, call the ListDeleteItem function to delete the current number from a list. If there are no more elements to delete, these functions return the END_OF_LIST constant.

Note that since ListDeleteString and ListDeleteItem delete the current element, you must reset the current element to the element that you want deleted. After deletion, the next element in the list becomes the current element. You reset the element by any of the methods described in Traversing Lists.

The example below illustrates the use of several list functions, including ListDeleteString. The ListDeleteItem function is used in the same manner, except that the list is a number list and the variables are number variables.

// Create the empty list of strings.

listID = ListCreate (STRINGLIST);

 

if (listID = LIST_NULL) then // Test for a valid list.

    MessageBox ("List not created", SEVERE);

endif;

 

// Add some strings to the list.

szString = "String 1";

ListAddString (listID, szString, AFTER);

szString = "String 2";

ListAddString (listID, szString, AFTER);

szString = "String 3";

ListAddString (listID, szString, AFTER);

 

// Delete the current string.

ListDeleteString (listID);

 

// Reset the current string in the list.

lResult = ListCurrentString (listID, svString);

 

// svString contains "String 2."