Conditional
compilation
Description
The use of conditional compilation directives causes the
PowerBuilder preprocessor to parse blocks of code before they are passed
to the compiler.
Syntax
|
1 2 3 4 5 6 7 |
#IF { NOT } DEFINED predefined_symbols THEN action1 { #ELSEIF DEFINED predefined_symbols THEN action2 } { #ELSE action3 } #END IF |
|
Parameter |
Description |
|---|---|
|
predefined_symbols |
A predefined identifier or a combination of |
|
action1, action2, action3 |
The action you want performed if the condition in the |
Usage
Conditional compilation enables you to include PowerScript code for
a specific target type or set of target types in an application. You can
also include debug code in your application and specify in the Project
painter whether it will be included in your application’s executable
file.
The preprocessor substitutes blank lines for statements with a
leading number (#) sign character. It passes the code in the
action statements to the compiler or converts it to blank lines depending
on whether the condition in the previous preprocessor directive was
met.
The following table displays the predefined symbols, the project
types to which they correspond, and their effects on the code passed to
the compiler.
|
Predefined symbols |
Target type |
Code in this processing block |
|---|---|---|
|
PBNATIVE |
Standard PowerBuilder client-server or distributed |
Fully parsed for the standard application and |
|
PBWEBSERVICE |
.NET Web Service component targets |
Fully parsed for .NET Web Service targets and |
|
DEBUG |
All PowerBuilder standard and .NET |
When a project’s Enable DEBUG Symbol check box is |
You can use the NOT operator to include code for all target types
that are not of the type that you specify, and you can use AND and
OR operators to combine symbols. For example, code that follows this
statement will be parsed for all targets except standard PowerBuilder
applications:
|
1 |
#if NOT defined PBNATIVE then |
Comments can be added to conditional code blocks if they are
preceded by double slash marks ( // ) in the same line of code. You cannot
use the PowerScript line continuation character ( & ) in a conditional
code statement. You must use it in code that you embed in the conditional
block when you use more than one line for a single line of code.
Limitations and error
messages
Conditional compilation is not supported in DataWindow syntax, or in
structure or menu objects. You cannot edit the source code for an object
to include conditional compilation blocks that span function, event, or
variable definition boundaries.
You must rebuild your application after you add a DEBUG conditional
block.
The following table shows the types of error messages displayed for
incorrect conditional compilation code.
|
Error message |
Description |
|---|---|
|
Invalid if statement |
#if statement without a defined symbol, with an |
|
#end if directive expected |
#if statement without an #end if |
|
Unexpected preprocessor directive |
Caused by an #else, #elseif, or #end if statement |
|
Preprocessor syntax error |
Caused by including text after an #else or |
Examples
When you run or debug the application in the development
environment, the following code is always parsed and you always see the
message box. When you run the executable file, the code is parsed only if
the DEBUG symbol is enabled on the General page in the Project
painter:
|
1 2 3 |
#if defined DEBUG then MessageBox("Debugging","Ctr value is " + string(i)) #end if |