Building Functions
InstallShield 2020
Typically, functions are declared at the top of the file, and the body is defined at the bottom of the file. After you declare a function prototype, you need to define the function itself in the function block. Each function block contains only one function.
To build a function:
1. | Start the function body with the keyword function. |
2. | Type the return value data type used in the function prototype, or type void if the function prototype specifies a return type of void (which indicates that the function does not return a value). If the function prototype does not specify a return type, it is not necessary to enter one here. |
3. | Type the function name. |
4. | To the right of the function name, type the names of the arguments that you are using in parentheses. The arguments must correspond in data type to the parameters that you declared in the declare block. |
Note:InstallScript functions do not allow you to pass an assignment statement as a parameter. In addition, you cannot use the && or || operators within an argument to a function.
Steps 1 and 2 create the function header. Function headers do not end with a semicolon in InstallScript.
5. | Declare any local variables that you will use in the function. Then type the keyword begin on a line by itself, without punctuation. |
6. | After the begin line, add whichever statements you need in order to accomplish your particular task. |
You can also use a return statement, particularly if you want to return a specific value from the function. See below for information on returning values from a function.
7. | End your function with the keyword end. |
A sample function block is shown below:
function GetPathParts(szFullPath, svDrv, svPath, svName)
LONG lResult;
begin
lResult = ParsePath(svDrv, szFullPath, DISK);
if (lResult = 0) then
lResult = ParsePath(svPath, szFullPath, DIRECTORY);
endif;
if (lResult = 0) then
lResult = ParsePath(svName, szFullPath, FILENAME);
endif;
return lResult;
end;
Note:User-defined functions can return a value with a return statement. Other types of data can be returned in parameters that have been declared with the BYREF operator.
See Also
#include (including the contents of another script in the main installation script)