Welcome!

Helping Developers Master PowerBuilder Classic and .NET

Yakov Werde

Subscribe to Yakov Werde: eMailAlertsEmail Alerts
Get Yakov Werde via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Related Topics: Enterprise Architecture, Enterprise Application Performance

Blog Post

PowerObjectParm and System.Object Types

Workarounds for .NET and PowerScript integration

I was working on a POC app that integrates a .NET assembly with a PowerBuilder 12.1 WPF app when I ran across this issue. Most anyone doing any assembly integration will discover the same thing. In order to save you some time and bother I’m writing my findings and suggesting a couple of workarounds here.

Background
One on the key changes to the PowerScript class hierarchy was the insertion of System.Object as the ancestor of PowerObject. Object is now the grand ancestor of all PowerScript Classes. Figure 1 shows that PowerObject now has System.Object members.

Figure 1: PowerObject members

In object oriented terms this inheritance change means two things. (1) A PowerObject IS A System.Object, (2) A System.Object IS NOT a PowerObject

This code is valid

PowerObject Lpo


System.Object Lso


Lpo = CREATE PowerObject


Lso = Lpo


But this code is NOT valid

PowerObject Lpo


System.Object Lso


Lso = CREATE System.Object


Lpo = Lso


Another key piece of the puzzle is that the data type of Message.PowerObjectParm is PowerObject

Discovery

All I wanted to do was pass a reference to an object defined in an assembly to a Response window at open time.

I got these two compiler errors:

w_benchmark.srw(778,15): w_benchmark.cb_machine.clicked.1  C0327: The best overloaded method match for 'openwithparm(ref window, double)' has some invalid arguments.

w_machine.srw(91,12): w_machine.open.1  C0008: Incompatible types in assignment: n_registry, powerobject.


Seems like the compiler interprets .NET reference variables as double!

To find out what was going on I simplified the code by removing the assembly from the picture and creating a simple two window application.  Window1 creates an URI object and passes to Window 2 on open

Here's the code in the first window's open event:

System.Uri Ln_uri


Ln_uri = create System.Uri("http://www.google.com")


OpenWithParm( w_catch , Ln_uri )


 

Sure enough, I got the same compiler error message, "The best overloaded method match for 'openwithparm(ref window, double)' has some invalid arguments"

Here's the code from the 2nd window's open event

System.Uri Ln_uri


Ln_uri = Message.PowerObjectParm

 

As I predicted, the same compiler error was reported.  "Incompatible types in assignment: System.Uri, powerobject"

Recommendation

The upshot is that it is currently not possible to pass .NET object types using the OpenWith  PowerScript function set.

Two possible workarounds are:  (1) Code a method that you call immediately after the open that takes a System.Object as an argument.  (2) Define a CCUO that contains a System.Object type instance variable.  Create the CCUO, assign a reference to its instance variable and pass the CCUO using the OpenWith...( method call.

Method 2 is best used when opening Response windows where because of their modality you don't have the option of calling a method.  Method 1 is best for non Response type windows and other types of Visual User objects

I passed along a suggestion to engineering to change the data type of PowerObjectParm to System.Object.  Do you agree this is a the best solution to the problem?

More Stories By Yakov Werde

Yakov Werde, a 25 year IT industry veteran, is a member of TeamSybase and the newly formed Sybase Customer Evangelist Team. Yakov is a recognized author, speaker and trainer who has been designing and delivering PowerBuilder, .NET, EaServer, Web App Development, and Java training for over 14 years to corporate, military and government developers. Prior to discovering his aptitude as an educator, Yakov worked as an architect, project manager and application coder in the trenches of application software development. Yakov holds a Masters in Education with a specialty in instructional design for online learning from Capella University and a BS in math and computer science from Florida International University. Yakov, managing partner of eLearnIT LLC (www.elearnitonline.com), authors and delivers workshops and web based eLearning tutorials to guide professional developers toward PowerBuilder Classic and .NET mastery. Follow Yakov on Twitter as @eLearnPB