PBDR.COM

About   -   Contact   -   Purchase   -   Search   -   What's New

 
 
COM Access to PowerBuilder Objects
A new feature added to PowerBuilder 5.0 is the ability to run a PowerBuilder object as a COM (OLE) automation object. Because of the way COM is designed any COM automation object can also be a DCOM object which allows for distributed objects calls across a network. NOTE with PB5 you would need to install your object under a transaction server such as Jaguar or MTS to call PB objects via DCOM.

Because the object is registered under COM it means that any COM compatible language can access your objects methods. This includes languages such as Visual Basic and Visual C++ as well as Microsoft's new Internet tool Visual Interdev. Under these products you can create and reference PowerBuilder objects as if they were part of the native product.

So how is this achieved? Create a non visual user object in PowerBuilder and save it to the library. You can use inheritance but to make things easy make sure that all the ancestors and aggregate objects are in one PowerBuilder library. The non visual objects that you expose are not limited to the nonvisualuser object and can include datastores. Imagine the power of the datawindow in visual basic!

In designing your objects I would strongly recommend that you do not expose a datastore as a COM object. This is because you want to retain control of the object and only let the user of your object perform the functions that you want them to perform. Imagine if they filtered the records and you performed an update not realizing that half of the records were not updated successfully.

I have created an object nc_com_ds which is exposed to the outside world and encapsulates a private datastore variable. I then allow simple getitem and setitem calls on the data window using a custom get/set itemany function. Click here to see an example of the code.

Once you have completed the object you need to compile it either as a PBD or as a DLL. Then register the object under COM. To register the object under COM download a copy of PBComReg.

Make sure you copy the object to the local hard drive of the machine where you are running the object from. If you do not you may get access violations on the object if it is accessed by a guest user (for example from IIS running active server pages). If you do move the object then you will need to alter the location entry of the object in the registry or the REG file before using the object.

You can then access the object and all public methods on the object from any COM language. You can also access public methods of public aggregated objects from the COM language for example here I'm calling a getitem method of a datastore inside a PowerBuilder business object inside VBScript:

pbbusinessobject.datastore.getitem( 1, "column" )

 

Top of Page

Legal Notice

Ken Howe 2011