Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Connection Type

Conditional Compilation – PB Docs 120 – PowerBuilder Library

Conditional Compilation – PB Docs 120


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:

Default preprocessing symbols for conditional compilation

Preprocessing symbols

Project type

Code in this processing block

PBNATIVE

PowerBuilder client-server or distributed
applications

Fully parsed by the PowerScript compiler.
It is converted to blank lines for the pb2cs compiler.

PBWEBFORM

.NET Web Forms application

Fully parsed by the pb2cs compiler for
.NET Web Forms targets only. It is converted to blank lines for
the PowerScript compiler and all other types of .NET targets.

PBWINFORM

.NET Windows Forms applications

Fully parsed by the pb2cs compiler for
.NET Windows Forms targets only. It is converted to blank lines for
the PowerScript compiler and all other types of .NET targets.

PBWEBSERVICE

.NET Web Service component targets

Fully parsed by the pb2cs compiler for
.NET Web Service targets only. It is converted to blank lines for
the PowerScript compiler and all other types of .NET targets.

PBDOTNET

.NET Web Forms and Windows Forms applications,
and .NET Assembly and .NET Web Service components

Fully parsed by the pb2cs compiler for
all .NET target types. It is converted to blank lines for the PowerScript
compiler.

DEBUG

Standard PowerBuilder targets and all
.NET application and component targets

When a project�s Enable DEBUG Symbol
check box is selected, code is fully parsed in deployed applications
by the PowerScript compiler, or for .NET targets, by the pb2cs compiler.
Code is converted to blank lines when the check box is cleared.

Note:

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

You indicate a conditional block of code with a statement
of the following type, where symbolType is
any of the symbols defined by PowerBuilder:

You can use the NOT operator to include code for all target
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:

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.

The closing statement for a conditional block is always:

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:

Types of error messages returned by the preprocessor

Error message

Description

Invalid if statement

#if statement
without a defined symbol, with an incorrectly defined symbol, or
without a then clause

#end if directive expected

#if statement
without an #end if statement

Unexpected preprocessor directive

Caused by an #else, #elseif,
or #end if statement
when not preceded by an #if statement

Preprocessor syntax error

Caused by including text after an #else or #end if
statement
when the text is not preceded by comment characters (//)

  • 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.

Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x