Comments
L W wrote: Dear Sir, Please do forward a Google Wave Invitation to lvw.iv4 (at) gmail (dot) com, at your earliest convenience? Much appreciated!
Cloud Computing
Conference & Expo
November 2-4, 2009 NYC
Register Today and SAVE !..

SYS-CON.TV
Today's Top SOA Links


Implementing an Intellisense-like System Using PowerBuilder and the .NET Framework
Making PowerBuilder more productive

Pbintelli is an application that helps PowerBuilder developers write code faster and more accurately.

The principal features implemented are:

  • Shows variables, functions, and events of PowerBuilder's objects
  • Pastes selected variables, functions, or events directly into the PowerBuilder editor
  • Shows DataWindow fields
  • Shows enumerated values
  • Acts as a code repository
  • Copies application files
  • Creates PBR files
  • Acts as an object finder
  • Can be used as an system/API function finder
All these features can be called directly from the PowerBuilder IDE. In some cases PBintelli acts like an IntelliSense system and presents a list of insertable objects/functions. In others the developer can invoke the functionality by selecting an item from the context menu that appears once the F6 key is pressed. In this article the focus is on the implementation of the IntelliSense feature. I will describe the techniques used to achieve this behaviour.

Overview
The first problem, if you want to write an add-in for PowerBuilder, is the interaction between your application and the PowerBuilder environment. Currently there's no API defined for interacting with the PowerBuilder IDE, so the only thing to do is to use some kind of workaround.

There are a number of applications that run in background and detect user activity. PBintelli uses a keyboard hook to trap when the user presses a key. Naturally only the actions fired from the PowerBuilder code editor are significant; all others are ignored. The hook is automatically installed when the object is created, but you can stop and start the hook from listening using the appropriate buttons. A hook lets you insert a callback function that intercepts certain Windows messages and lets you respond with some action. The hook is written using C# language (you need a language that supports pointers to functions) and uses the Windows system function SetWindowsHookEx.

When a key is pressed in PowerBuilder code editor the background application receives a notification with the key-code pressed and the Window handle that raised the event. The handle is important because it makes it possible to send messages to the code editor Window and obtain information such as the text displayed and the caret position. (See the article entitled "Custom Common Dialogs Using SetWindowsHookEx" from the April issue of PBDJ for more information on creating hooks).

The program then parses the text in the script editor and calls a COM object that was written in PowerBuilder. The COM object uses the PowerBuilder Class Definition Object Library functions to analyse the text. To use these functions it's necessary to reference a library list. The COM object determines the library list to use by looking for the last workspace saved in the PB.INI file. The COM object is initialized with the library list every time the current target changes. For example, here's the C# code that PBintelli uses to find the signature of a user function:

PBintelli_90.COClass_PBintelli_90Class obj9;
obj9 = new PBintelli_90.COClass_PBintelli_90Class();

obj9.of_settolibrerie(arg_lib);
ret = obj9.of_getfunctionsignature (function_name, ref ls_signature);

The Function_name is a string containing the name of the function and ls_signature is an output parameter of the string type that receives the signature.

There's a wrapper class that manages the different versions of PowerBuilder (there's a different COM object for every supported version of PowerBuilder), if the version changes the class internally uses the correct COM object for that version. The information returned by the COM object is then exposed using an interface written in C#.

About Tracogna Roberto
Tracogna Roberto is a project manager at Multimedia s.r.l, an Italian IT company that provides medical software products. He has more than 10 years of experience in software design, development, and implementation. Tracogna holds a degree in computer science from the Department of Mathematics and Computer Science at the University of Udine in Italy.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE