Conditional Compilation
Use the number sign (#) at the start of a line or block
of code in PowerBuilder to mark the code for specialized processing
prior to PowerScript compilation.
Each line of code or block of
conditional code set off by a leading number sign is automatically
parsed by a PowerBuilder preprocessor before it is passed to the
design-time PowerScript compiler or the PowerBuilder-to-C# (pb2cs)
compiler.
Preprocessing symbols
There are
six default code-processing symbols that affect the code passed to
the PowerScript compiler at design time. Four of these symbols correspond
to different PowerBuilder target types, one applies to all .NET target
types, and one applies to both standard PowerBuilder and .NET target
types.
The preprocessor enables PowerBuilder to compile project code
specific to a particular deployment target without hindering the
compiler�s ability to handle the same code when a different
deployment target is selected.
The preprocessor substitutes blank lines for all declarative
statements and conditional block delimiters having leading number
sign characters before passing the code to the PowerScript compiler
or the pb2cs compiler. The contents of the conditional
blocks are converted to blank lines or passed to the compiler depending
on which preprocessor symbol is used.
This table shows the default
preprocessing symbols, the project types to which they correspond,
and their effects on the code passed to the PowerScript compiler
engine or the pb2cs compiler:
Preprocessing symbols |
Project type |
Code in this processing block |
---|---|---|
PBNATIVE |
PowerBuilder client-server or distributed |
Fully parsed by the PowerScript compiler. |
PBWEBFORM |
.NET Web Forms application |
Fully parsed by the pb2cs compiler for |
PBWINFORM |
.NET Windows Forms applications |
Fully parsed by the pb2cs compiler for |
PBWEBSERVICE |
.NET Web Service component targets |
Fully parsed by the pb2cs compiler for |
PBDOTNET |
.NET Web Forms and Windows Forms applications, |
Fully parsed by the pb2cs compiler for |
DEBUG |
Standard PowerBuilder targets and all |
When a project�s Enable DEBUG Symbol |
The PBWPF preprocesser can be used for WPF Window Application
targets in the PowerBuilder .NET IDE. PowerBuilder Classic ignores
the scripts inside these code blocks, except when the NOT operator
is used with this preprocesser. The PBDOTNET and DEBUG code blocks
are valid for both PowerBuilder Classic and PowerBuilder .NET.
Conditional syntax
of the following type, where symbolType is
any of the symbols defined by PowerBuilder:
1 |
#IF defined <var>symbolType</var> then |
types that are not of the symbol type that you designate. For example,
the following code is parsed for all targets that are not of the
type PBNative:
1 |
#IF NOT defined PBNATIVE then |
You can also use #ELSE statements
inside the code block to include code for all target types other
than the one defined at the start of the code block. You can use #ELSEIF
defined symbolType then statements
to include code for a specific target type that is different from
the one defined at the start of the code block.
1 |
#END IF |
Comments can be added to conditional code if they are preceded
by double slash marks ( // )
in the same line of code. Although 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,
in structures, or in 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.
This table shows
the types of error messages displayed for incorrect conditional compilation
code:
Error message |
Description |
---|---|
Invalid if statement |
#if statement |
#end if directive expected |
#if statement |
Unexpected preprocessor directive |
Caused by an #else, #elseif, |
Preprocessor syntax error |
Caused by including text after an #else or #end if |
- Surrounding Code in a .NET Block
Because the main PowerBuilder compiler does not recognize the classes imported from .NET assemblies, you must surround the code referencing those classes in a conditional compilation block for a .NET application. - PowerScript Syntax for .NET Calls
When you make calls to .NET assemblies or their methods or properties from PowerBuilder, you must follow PowerScript syntax rules. The following syntax rules are especially important for C# developers to keep in mind: - Adding .NET Assemblies to the Target
To call methods in .NET assemblies in your .NET application, you need to import the assemblies into the target. - Datatype Mappings
When you call methods from managed assemblies in PowerScript, you must use PowerBuilder datatypes in any method arguments or return values. - Support for .NET language features
When you use conditional blocks of code for the .NET environment, you can take advantage of features that are not available in the PowerBuilder Classic application environment - Limitations
There are some important limitations on the code you can enclose in conditional compilation blocks. - Handling Exceptions in the .NET Environment
The PowerBuilder to .NET compiler changes the exception hierarchy used by the native PowerScript compiler.