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:
Instantiating a class
Even when you are referencing a .NET type in a .NET conditional
block, you must use the PowerScript create syntax. The following
line instantiates a .NET type from the logger namespace:
1 |
ls = create logger.LogServer |
Note that a single dot (.) is used as a namespace separator
in .NET conditional blocks.
Compound statements
as �if�, �for�, or �switch�.
The preprocessors for .NET applications signal an error if C# compound
statements are used. For example, you cannot use the following C# statement,
even inside a .NET conditional block: for (int
I=0;I<10;I++).
The following script shows the PowerScript equivalent, with looping
calls to the .NET WriteLine method, inside a
PBDOTNET conditional block:
1 |
#IF Defined PBDOTNET THEN |
1 |
int i |
1 |
for I = 1 to 10 |
1 |
System.Console.WriteLine(i) |
1 |
next |
1 |
#END IF |
PowerScript keywords
as �System� and �type�. To distinguish
the .NET Framework usage from the PowerBuilder keyword, you can
prepend the @ symbol. For example, you can instantiate
a class in the .NET System namespace as follows:
1 2 3 4 |
#IF Defined PBDOTNET THEN @System.Collections.ArrayList myList myList = create @System.Collections.ArrayList #END IF |
The PowerBuilder preprocessor includes logic to distinguish
the .NET System namespace from the PowerBuilder System keyword,
therefore the use of the @ prefix is optional as a namespace
identifier in the above example. However, you must include the @ identifier
when you reference the .NET Type class in PowerScript
code (@System.@Type or System.@Type).
Also, if you use a PowerBuilder keyword for a .NET namespace name
other than System, you must prefix the namespace name with the @ identifier.
Although PowerBuilder can support .NET Framework classes and namespaces,
it does not support .NET keywords. For example, you cannot use the
.NET keyword typeof, even if you prepend it
with the @ identifier.
Line continuation and termination
You must use PowerScript rules when your script extends beyond
a single line. The line return character indicates the end of a
line of script except when it is preceded by the ampersand (&) character.
Semicolons are not used to indicate the end of a PowerScript line.
Rules for arrays
not after the array datatype. You cannot initialize an array before
making array index assignments. PowerBuilder provides automatic
support for negative index identifiers. (In C#, you can
have negative index identifiers only if you use the System.Array.CreateInstance
method.) The following example illustrates PowerScript coding for
an array that can hold seven index values. The code is included
inside a conditional compilation block for the .NET environment:
1 |
#IF Defined PBDOTNET THEN |
1 |
int myArray[-2 to 5] |
1 |
//in C#, you would have to initialize array |
1 |
//with code like: int[] myArray = new int[7] |
1 |
myArray[-1]=10 //assigning a value to 2nd array index |
1 |
#END IF |
In PowerBuilder, unbounded arrays can have one dimension only.
The default start index for all PowerBuilder arrays is 1. The GetValue method
on a C# array returns 0 for a default start index identifier,
so you would call array_foo.GetValue
(0) to return the first element of the array array_foo. However,
after a C# array is assigned to a PowerBuilder array, you
access the elements of the array with the PowerBuilder index identifier.
In this example, you identify the first element in PowerScript as array_foo[1].
Case sensitivity
.NET is case sensitive, but PowerBuilder is not. The .NET Framework
does provide a way to treat lowercase and uppercase letters as equivalent,
and the PowerBuilder to .NET compiler takes advantage of this feature.
However, if the .NET resources you are accessing have or contain names
that differ only by the case of their constituent characters, PowerBuilder cannot
correctly compile .NET code for these resources.
Cross-language data exchange
Code inside a .NET conditional compilation block is not visible
to the main PowerBuilder compiler. If you use variables to hold
data from the .NET environment that you want to access from outside
the conditional block, you must declare the variables outside the conditional
block. Variables you declare outside a .NET conditional block can remain
in scope both inside and outside the conditional block.
Declaring enumeration constants
You use a terminal exclamation mark (!) to access enumeration
constants in PowerScript. For information about using enumeration
constants in the .NET environment, see User-Defined Enumerations.