Tech Articles


Using Visual .NET Components in PowerBuilder


Microsoft recently released the Interop Forms Toolkit 2.0 in order to allow "developers to incorporate VB.NET Forms and Controls into their VB6 applications" (www.microsoft.com/downloads/details.aspx? FamilyID=934de3c5-dc85-4065-9327-96801e57b81d&DisplayLang=en).

The interesting thing is that it operates by automatically generating a COM Callable Wrapper (CCW) for the VB.NET forms and controls. That means that the .NET visual user controls are not only available to VB6, but to any Win32 application that supports COM, including PowerBuilder.

To test it out, I wrote a simple gradient user object in VB.NET (see Listing 1) and deployed it as an interop user control. I then added it to a PowerBuilder 10.5 window as an ActiveX (see Figure 1).

Everything on the window, with the exception of the gradient control, is standard PowerBuilder stuff. After some simple calculations to determine the combined RGB value the user has selected through the sliders and display it, it is applied to the gradient control through the following (of_calcstart and of_calcend are the routines used to calculate the RGB values):

long ll_start, ll_end
ll_start = of_calcstart()
ll_end = of_calcend()

//This will actually cause two repaints, but I don't care
ole_1.object.StartColor = ll_start
ole_1.object.EndColor = ll_end

The reason there are two repaints is because I force a repaint of the control whenever either the start or end color for the gradient is changed. The repaint happens fast enough so the user doesn't notice there were two.

Note that this technique will work not only for controls that you create in VB.NET, but also for third-party controls that can be used in VB.NET. For example, Figure 2 shows Dundas Charts working within a PowerBuilder window after being exposed as an interop control. Similarily, Figure 3 shows Infragistics' WinChart control operating in a PowerBuilder window.

The Interop Toolkit also allows you to expose VB.NET Forms as ActiveX controls (and has since the original 1.0 version), but I can't see much use for that. The important change with the 2.0 version is support for deploying controls.

Note that if you reference a third-party control in your user control, you will need to provide your own methods that will in turn interact with the third-party control. Just because the third-party control is visually exposed through the control doesn't mean that its properties and methods have been exposed.

In an earlier PBDJ article on CCWs I mentioned how manifests can be used so that such controls can be deployed as side-by-side assemblies and invoked through registry-free COM. That simplifies deployment by not requiring changes to the registry or the GAC. One additional significant feature of the Interop Toolkit is that it automatically generates the manifest information you would need if you opted for that deployment method.

Finally, if you're a bit of a C# snob (as I am), you might be initially put off that Microsoft only released the toolkit with support for VB.NET. Fortunately, a couple of people decided to take matters in their own hands and made additional templates for the toolkit available on the CodeProject Website that make the functionality available in C# as well. In particular, Leon Langleyben made one available just after the release of the 1.0 version of the toolkit that implemented forms (https://www.codeproject.com/kb/vb-interop/vb6interoptoolkit2.aspx), and more recently James Ashley made one available for the 2.0 version of the toolkit and controls (https://www.codeproject.com/Articles/15690/VB-C-Interop-Form-Toolkit).

To be honest, this isn't an ideal solution. What it does allow you to do is take advantage of Visual .NET controls in PowerBuilder now, until such time as PowerBuilder 12 is available and directly supports them.

 

--This article was originally published on PBDJ.

Comments (0)
There are no comments posted here yet

Find Articles by Tag

RibbonBar Event Handling Window RichTextEdit Control REST 32-bit Encryption Performance XML DataWindow JSON SQL Server InfoMaker C# TortoiseGit Repository Array WebBrowser Database Database Table Data Application SnapDevelop Class CoderObject License TLS/SSL Web API Database Painter DataWindow DLL Menu Source Code Syntax OLE Database Profile NativePDF OAuth Validation Sort PDF Graph JSONParser Database Table Schema CI/CD OrcaScript Android DragDrop Debugger Data SVN 64-bit PDFlib Mobile Web Service Proxy Expression Outlook Charts Linux OS .NET DataStore Script Source Control IDE Automated Testing Design Import PowerBuilder Configuration Export JSON SOAP SqlModelMapper Trial BLOB Database Table Platform Encoding UI Themes Deployment PowerBuilder Compiler Resize Authentication Migration COM Debugging Windows 10 Icons .NET Assembly Transaction OAuth 2.0 Event RibbonBar Builder PowerScript (PS) Interface Filter JSONGenerator ODBC .NET Std Framework Git Database Connection TreeView iOS ActiveX Elevate Conference Windows OS Jenkins Text Azure UI Event Handler UI Modernization PBDOM SDK JSON Error Bug SqlExecutor Oracle Export Stored Procedure TFS WinAPI File Variable PowerBuilder (Appeon) Service SnapObjects External Functions PostgreSQL ODBC driver PFC SQL DataType Model PowerServer Mobile Open Source Database Object MessageBox Import JSON Branch & Merge CrypterObject API RESTClient Debug GhostScript HTTPClient Messagging Authorization PostgreSQL Excel Icon PowerServer Web Installation DevOps Testing