Welcome!

PowerBuilder Authors: Chris Pollach, Yeshim Deniz, Jayaram Krishnaswamy, Kevin Benedict, Avi Rosenthal

Related Topics: PowerBuilder

PowerBuilder: Article

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

More Stories By 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.

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.