Creating and Destroying Lists

InstallShield 2026

Before creating a list, decide which type of list you want to build: a string list or a number (item) list. To create the list, call the ListCreate function:

// This builds the list head for a string list.

listID1 = ListCreate (STRINGLIST);

–or–

// This builds the list head for a number (item) list.

listID2 = ListCreate (NUMBERLIST);

ListCreate automatically builds the head of the list and returns its ID number. The ID is used in all subsequent functions that operate on the list. Therefore, you must always create a list using ListCreate before you use any other list function. You must store the return value from ListCreate in a variable of type LIST or type LONG.

This fragment creates a number list and then a string list. It also tests each one to make sure that the lists were created successfully.

// This creates an empty list for strings.

listID1 = ListCreate (STRINGLIST);

 

if (listID1 = LIST_NULL) then

      MessageBox ("Unable to create the string list", SEVERE);

endif;

 

// This will create an empty list for numbers.

listID2 = ListCreate (NUMBERLIST);

 

if (listID2 = LIST_NULL) then

    MessageBox ("Unable to create the number list", SEVERE);

endif;

When you are finished using a list, you will typically want to destroy the list to free the memory for other uses. ListDestroy destroys the list and its contents. This example creates a list referenced by listID, adds a string to the list, and then destroys the entire list.

listID = ListCreate (STRINGLIST);

 

if (listID = LIST_NULL) then

    MessageBox ("Unable to create list.", SEVERE);

    abort;

endif;

 

ListAddString (listID, "This is a string in the list", AFTER);

ListDestroy (listID);

If you do not destroy a list using ListDestroy, the list will be destroyed when the installation is complete. If the list is local to a function, the list is destroyed when the function returns control to the calling code.

See Also