Adding a ScriptDefinedVar Property to Your Object

InstallShield 2013

Several of the objects included in InstallShield have a ScriptDefinedVar property. This property enables you to set at run time the value of a script-defined variable that you used to define a path (for example, <MYSERVICEFOLDER>\MyService.exe) at design time. For example, main script code like the following lets the end user specify the value of <MYSERVICEFOLDER>:

/* Get a reference to the object that is named

"New Custom Object 1" in the Components pane. */

set oObj = GetObject("New Custom Object 1");

 

/* Get folder selection from end user. */

svDir = TARGETDIR;

AskDestPath ( "" , "Specify folder for service files:" ,

    svDir , 0 );

 

/* Tell the object the desired value of <MYSERVICEFOLDER>. */

oObj.ScriptDefinedVar("<MYSERVICEFOLDER>") = svDir;

To include the ScriptDefinedVar property in your object script:

1. Open the InstallScript view.
2. In the InstallScript explorer, right-click Properties and click Add New Property. The Add New Property dialog box opens.
3. Make the following entries:
a. In the Property Name box, type the following:

ScriptDefinedVar

b. In the Data Type list, select String (since you will be writing string data to the property).
c. In the Access Method list, select Read/Write. (You can select Write Only instead if you are certain users of the object will never want to check the current value of the property from their main script.)
4. Click OK to close the dialog box and automatically add all the necessary code to your object script.
5. Make the following changes to the property script code that was automatically added:
a. Open the InstallScript view.
b. In the InstallScript explorer, under Properties, double-click ScriptDefinedVar to move the script editor pane’s insertion point to the ScriptDefinedVar declaration. Add a string parameter to the declaration—that is, change the declaration from this:

property(get,put) STRING ScriptDefinedVar();

to this:

property(get,put) STRING ScriptDefinedVar( STRING );

c. In the InstallScript explorer, under Functions, double-click get_ScriptDefinedVar to move the script editor pane’s insertion point to the get_ScriptDefinedVar function block. Find the following function block:

function STRING get_ScriptDefinedVar()

begin

    return m_strScriptDefinedVar;

end;

Change it to this:

function STRING get_ScriptDefinedVar( szScriptVar ) /* Add string argument. */

begin

    return TextSub.Value( szScriptVar ); /* Get value associated with szScriptVar. */

end;

d. In the InstallScript explorer, under Functions, double-click put_ScriptDefinedVar to move the script editor pane’s insertion point to the put_ScriptDefinedVar function block. Find the following function block:

function void put_ScriptDefinedVar(newVal)

begin

    m_strScriptDefinedVar = newVal;

end;

Change it to this:

function void put_ScriptDefinedVar( szScriptVar, newVal ) /* Add string argument. */

begin

    TextSub.Value( szScriptVar ) = newVal; /* Associate newVal with szScriptVar. */

end;