Welcome!

Search Authors: Mark O'Neill, Pat Romanski, Xenia von Wedel, Don Nelson, Corey Roth

Related Topics: PowerBuilder

PowerBuilder: Article

PowerBuilder's .NET Strategy

PowerScript language enhancements for .NET application development

A multi-dimensional array will be enhanced to be declared without specifying the array bounds. For example, int arr[,] which is a two-dimensional integer array.

At runtime, users can create a multidimensional array as follows:

arr = create int[4, 2 to 5]

which creates a two-dimensional integer array, with indexes of the two dimensions being 1 to 4 and 2 to 5.

Jag-array will be allowed to be declared. For example, int arr[][], which is a integer jag-array.

At runtime, users can create a jag-array as follow:

arr = create int[3][]
arr[1] = create int[5]
arr[2] = create int[20]
arr[3] = create int[10]

The first line creates an array with three elements, each of type int[] . The subsequent lines then initialize the three elements with references to individual array instances of varying lengths.

In .NET, a delegate type represents references to methods with a particular parameter list and return type. Delegates are similar to the concept of function pointers in some languages, such as C, but unlike function pointers, delegates are object-oriented and type-safe. In PB12, users will be able to make use of the .NET delegate type to cooperate with native PowerScript code.

The following example declares and uses a delegate type named Function in an imported .NET assembly.

.NET delegate declaration in C#:

delegate double Function(double x);

Consuming this delegate type in PowerScript:

public function double[] Apply ((double a[], Function f)
double result[]
for i = 0 to i < a.Length step 1
result[i] = f(a[i])
next
return result
end function
public function double Multiply(double x)
return x * factor;
end function
public function test()
double a[] = {1.0,2.0,3.0,4.0,5.0}
double doubles[] = Apply(a, Multiply)
end function

In PB12, the standard NVO will be able to inherit from a .NET class, which will override all virtual and abstract methods, properties, indexers, and events defined in the .NET base class and implemented interfaces.

Table 1 provides an overview of the kinds of members of a .NET class that can be exposed in PB.

This syntax of calling PowerScript functions and events will also be used to call the functions and events of .NET class as follow:

{ objectname.} { type } { calltype } { when } name ( { argumentlist } )

In .NET, generics are classes, structures, interfaces, and methods that have placeholders (type parameters) for one or more of the types that they store or use.

A generic collection class might use a type parameter as a placeholder for the type of objects that it stores; the type parameters appear as the types of its fields and the parameter types of its methods. A generic method might use its type parameter as the type of its return value or as the type of one of its formal parameters. In PB12, users will be able to consume .NET generic classes and methods, if they conform to generic CLS rules. But defining a generic type and overriding a generic method won't be supported.

Here's an example of consuming generic type in PB:

System.Collections.Generic.SortedList<string, integer> teams
teams = create System.Collections.Generic.SortedList<string, integer>
teams["DEV"] = 30
teams["QA"] = 25

In PB12, users will be able to define a global enum type; the new enum painter will be similar to Structure Painter as shown below.

To define a local enum, users will have to open the object painter that has a local enum painter attached.

The following kinds of PB objects will be able to define local enum: Custom Class, Standard Class, Custom Visual, Standard Visual, Window, and Menu.

In PB12, the following kinds of PB objects will be able to specify which namespace the object group belongs to and which namespaces the object group is using: Custom Class, Standard Class, Custom Visual, Standard Visual, Window, Menu, Structure, Function, Interface, and Enum.

There are two ways to identify a unique name. The first one is to use qualified names. That's a namespace name followed by the scope-resolution operator (.) and then the name of either a nested namespace or a group and the name of a member of a group. For example:

MyPkg.MyNestedPkg.w_main`cb_1

The second way is to use a using directive:

Using pkg1[.pkg2[.pkg3]...]

A using directive allows a named type to be referred to by a simple name that consists of a single identifier.

Currently in PB, a default constructor event is used to instantiate object. When a PB NVO object is created at runtime, an auto-generated oncreate event will be triggered in which the default constructor event will be subsequently triggered.

But the default constructor event doesn't support overloading so it will lose its flexibility to instantiate and initialize a particular type of object.

In PB12, parameterized constructor events will be supported, but they will only apply to custom and standard NVO types.

The syntax will be as follows:

objectvariable = create objecttype[(arg1[,arg2]...)]

In .NET, the custom attribute is a class used to represent custom metadata.

In PB12, users will be able to define a custom attribute class, but only some .NET types and their corresponding PB types can be useable as an attribute parameter type.

The syntax will be enhanced to support defining and applying custom attributes as follow:

global type EventPrototype from System.Attribute usage [event]
end type
type variables
public string prototype
end variables
forward prototypes
subroutine EventPrototype(string prototype)
end prototypes
subroutine EventPrototype(string pt)
prototype = pt
end subroutine

[EventPrototype("pbm_lbndblclk")]
event clicked
end event

More Stories By Thomas Zang

Thomas Zang is a staff software engineer at Sybase. He works in the Singapore kernel team of the PB department and is in charge of the PowerScript language enhancement project in PB12.0.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.