GetLine Example

InstallShield 2019 » 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 GetLine function.

*

* GetLine is called in this script to read a text file line by

* line.

*

* Note: In order for this script to run properly, you must set

*       the preprocessor constants so that they reference an

*       existing text file on the target system.

*

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

 

#define EXAMPLE_FILE "Readme.txt"

#define EXAMPLE_DIR  "C:\\Windows"

#define TITLE_TEXT   "GetLine example"

 

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

#include "Ifx.h"

 

export prototype ExFn_GetLine(HWND);

 

function ExFn_GetLine(hMSI)

    STRING  szFileName, szPath, szText, svLine;

    NUMBER  nFlag, nFileHandle;

    LIST   listID;

begin

    

    // Create a list to store lines from the file.

    listID = ListCreate (STRINGLIST);

    

    // Set the file mode to normal.

    OpenFileMode (FILE_MODE_NORMAL);

    

    // Open the file for editing.

    OpenFile (nFileHandle, EXAMPLE_DIR, EXAMPLE_FILE);

    

    // Get lines from the file into the list.

    while (GetLine (nFileHandle, svLine) = 0)

        ListAddString (listID, svLine, AFTER);

    endwhile;

    

    // Close the file.

    CloseFile (nFileHandle);

    

    // Display the list.

    SdShowInfoList (TITLE_TEXT, EXAMPLE_FILE, listID);

    

    // Remove the list from memory.

    ListDestroy (listID);

 

end;