ListAddItem Example

InstallShield 2016 » InstallScript Language Reference

Note • To call this function in a Basic MSI setup, you must first create a custom action for the entry-point function, execute the custom action in a sequence or as the result of a dialog's control event, and then build the release.

/*--------------------------------------------------------------*\

*

* InstallShield Example Script

*

* Demonstrates the ListAddItem function.

*

* First, an empty list is created by a call to ListCreate.

* Then ListAddItem is called three times to add the numbers

* 1, 3, and 2 to the list.  Although the numbers are not added

* in ascending order, they are arranged in that order in the

* list by means of the placement flag that is passed in the

* third parameter of each call to ListAddItem.  After the list

* has been built, it is displayed.  Finally the current element

* is displayed.

*

\*--------------------------------------------------------------*/

 

#define TITLE "ListAddItem Example"

#define MSSG  "The following is a list of the items added:\n\n"

 

// Include Ifx.h for built-in InstallScript function prototypes.

#include "Ifx.h"

 

export prototype ExFn_ListAddItem(HWND);

 

function ExFn_ListAddItem(hMSI)

    NUMBER nvItem, nvResult;

    LIST   listID;

    STRING szMsg, svItem;

begin

 

    // Create an empty number list.

    listID = ListCreate (NUMBERLIST);

 

    //If an error occurred, report it; then terminate.

    if (listID = LIST_NULL) then

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

        abort;

    endif;

 

    // Add the number 1 to the list.

    if (ListAddItem (listID, 1, AFTER) < 0) then

        MessageBox ("First call to ListAddItem failed.", INFORMATION);

        abort;

    endif;

 

    // The integer 1, in position 1, is the current element.

    // Add the number 3 after the current element.

    if (ListAddItem (listID, 3, AFTER) < 0) then

        MessageBox ("Second call to ListAddItem failed.", INFORMATION);

        abort;

    endif;

 

    // The integer 3, in position 2, is the current element.

    // Add the number 2 to the list before the current element.

    if (ListAddItem (listID, 2, BEFORE) < 0) then

        MessageBox ("Third call to ListAddItem failed.", INFORMATION);

        abort;

    endif;

 

    // Retrieve and display the current element.

    ListCurrentItem (listID, nvItem);

    

    SprintfBox (INFORMATION, TITLE, "Current Item: %d", nvItem);

 

        // Start building the message to report the numbers.

        szMsg = MSSG;

 

        // Get the numbers and add them to the message.

        nvResult = ListGetFirstItem (listID, nvItem);

        while (nvResult != END_OF_LIST)

            NumToStr (svItem, nvItem);

            szMsg = szMsg + svItem + "  ";

            nvResult = ListGetNextItem (listID, nvItem);

        endwhile;

 

        // Display the numbers.

        MessageBox (szMsg, INFORMATION);

 

    // Remove the list from memory.

    ListDestroy (listID);

 

end;