String Size and Autosize

InstallShield 2020 » InstallScript Language Reference

InstallShield Autosizing

When you declare a string variable without a size specification, InstallShield automatically sizes a string buffer for that variable. The allocation for the buffer occurs when you first assign a string to the variable. If later, you assign a longer string to that variable, InstallShield increases the memory allocation to accommodate the longer string—up to the amount of available memory. However, if you later assign a shorter string to an autosized variable, InstallShield does not decrease the memory allocation.

Caution:InstallShield's autosizing feature does not work in typedef statements; you must specify the size of all STRING declarations in a structure.

Specifying a String Size

When specifying a string size, you must declare one character position for the null terminator. For example, if you want your string to hold up to 128 characters, you must declare it with a length of 129 to allow room for the null terminator. For this reason, the minimum size of a string is 2.

When you are using a string that you have declared with a size, you must be aware of how that string might be used with other strings. For example, consider the following function call:

  STRING szQuestion[20], szDefault[20], svResult[50];

 

begin

  szQuestion = "Enter company name";

  szDefault  = "My Software Company";

  AskText (szQuestion, szDefault, svResult);

The size of the string svResult should be greater than or equal to the size of the string szDefault. If not, then szDefault, if accepted, will not fit into the svResult variable returned by the function. The easiest way to avoid conflicts is to let InstallShield autosize all strings (except those in a typedef statement).

Caution:An autosized string variable that is passed by reference to a function is not autosized within the called function. If the function attempts to assign a value whose length is greater than the current size of that parameter, run-time error 401 occurs.

See Also