Creating a Property

InstallShield 2015

Properties can be useful in object scripts. In an object script, properties enable your object’s users to change certain settings of your object during either design time through the use of an InstallShield Object Wizard or during run time by passing parameters through script. Common properties include passing error messages from the object to the installation, getting the user name, or any information that your object needs during either run time or design time. For examples of how properties are used, see the inline help for any of the InstallShield objects included in your Objects view.

Note the following details about properties:

If a Boolean property’s value is set to TRUE, either by the object script or the script of the installation that includes the object, subsequent checks of the property’s value will show the value to be –1 rather than 1.
You cannot pass a LIST variable between an object and an installation script; you can, however, pass a string array.

Creating a Property

To create a property:

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. Define your property’s settings.
4. Click OK.

The Add New Property dialog box adds the following to your script:

A property declaration with the following syntax:

property(<procedures>) <property data type> <property name> ( );

<procedures> is get for a read-only property, put for a write-only property, and get,put for a read/write property. For example:

property(get,put) STRING MyProperty ( );

 

You can specify arguments for your property by adding the arguments’ data types inside the parentheses after the property name. For example:

property(get,put) STRING MyProperty ( NUMBER );

 

If you add argument data types to the property declaration, you must add corresponding argument variables to the definitions of the property’s procedure functions.

A declaration of a variable to store the property’s value within the script. For example:

STRING m_strMyProperty;

 

If you specify an array property in the Add New Property dialog box (by selecting the Array check box), two variables are declared: a variable of type VARIANT that stores the property’s value and an unsized array variable that is used in the InitProperties function block to initialize the property’s value. For example:

STRING arrayMyArrayProperty();

VARIANT m_arrayMyArrayProperty;

A statement, in the InitProperties function block, that initializes the variable that stores the property’s value. For example:

m_strMyProperty = "My Default Value";

 

If you specify an array property in the Add New Property dialog box (by selecting the Array check box), the variable that stores the property’s value is assigned the value of an array variable. For example:

m_arrayMyArrayProperty = arrayMyArrayProperty;

 

To initialize elements of the array property to non-null or nonzero values, add assignment statements for the array variable’s elements before the statement above. For example:

/* Resize the array variable, which is declared with no size. */

Resize ( arrayMyArrayProperty , 3 );

 

/* Assign values to the array variable's elements. */

arrayMyArrayProperty(0) = "zero";

arrayMyArrayProperty(1) = "one";

arrayMyArrayProperty(2) = "two";

 

m_arrayMyArrayProperty = arrayMyArrayProperty;

A function call, in the ReadProperties function block, to retrieve the property values stored in the property bag object. This call has the following syntax:

<ReadxxxxProperty> ( PropertyBag, "<property name>", <property value variable> );

 

<ReadxxxxProperty> is the ReadxxxxProperty function that is appropriate to the data type of the property’s value. For example:

ReadStringProperty( PropertyBag, "MyProperty", m_strMyProperty );

 

A function call, in the WriteProperties function block, to save the property values to the property bag object. This call has the following syntax:

<WritexxxxProperty> ( PropertyBag, "<property name>", <property value variable> );

<WritexxxxProperty> is the WritexxxxProperty function that is appropriate to the data type of the property’s value. For example:

WriteStringProperty( PropertyBag, "MyProperty", m_strMyProperty );

 

A function block or blocks defining the property’s procedures—that is, defining the actions that are executed when the property’s value is read or written to by a project containing the object or the object’s design-time wizard (if any)

A get_<property name> function is defined for a read-only or read/write property; a put_<property name> function is defined for a write-only or read/write property. For example:

function STRING get_MyProperty()

begin

    return m_strMyProperty;

end;

 

function void put_MyProperty(newVal)

begin

    m_strMyProperty = newVal;

end;

If you specify arguments for your property (by adding the arguments’ data types to the property declaration, inside the parentheses after the property name), you must add corresponding argument variables to the definitions of the property’s procedure functions. For example:

function STRING get_MyProperty( szAddedArgument )

function void put_MyProperty( szAddedArgument, newVal )

When you are adding arguments to the put_ function, place them before the newVal argument. The newVal argument takes the value that is written to the property by an assignment statement in the calling project or by the object’s design-time wizard (if any).

Note: The get_ and put_ functions must not be renamed; if they are renamed, your script will not function properly.