Tech Articles


Dynamic Runtime DataWindow Group Creation


Here’s a DataWindow tip…and a half.

Unless you want to dynamically build a DataWindow object from scratch at runtime (it’s do-able…but quite involved), there’s no direct way to create a group for a DataWindow object in an ad hoc manner. Here’s a workaround.

First, insert a computed field in an extant DataWindow object and give it an expression that’s an empty string. For the sake of this tip the computed field’s name will be “dynamicgroup”.

image

 

 

Read more

Updating the Datawindow Object Definition


I'm doing some work on an application to aid in the mass update of various datawindow attributes. It's not rocket science since you are dealing with a series of text files and doing some basic 'find and replace' operations. However, if you have ever worked on a project which has been around for a while you will notice that datawindows do not get 'migrated' when you upgrade to a newer version of PowerBuilder; the export syntax remains at the version in which the thing was last modified and saved.

Now you might think that using the LibraryExport and LibraryImport methods will do the trick but you would be mistaken. A newly imported datawindow object keeps the same version as when it was exported.

To accomplish the task you need to use the datawindow CREATE method.

Read more

Fast String Concatenation


I needed a way to build a string in a loop for import into a DataWindow but speed was important.

I created an object with functions that allows for string concatenation using a blob variable that is allocated once and no external function calls are needed.

To test my object I concatenated a string of 445 characters to a new string 500 times. The standard method seen here took 320 milliseconds:

ls_data = "-start-"
For li_idx = 1 To 500
	ls_data = ls_data + "-" + String(li_idx) + "-"
	ls_data = ls_data + is_string
Next

The test using my object seen here took only 20 milliseconds:

n_stringclass sc

sc.alloc(225000)
sc.copy("-start-")
For li_idx = 1 To 500
	sc.concat("-" + String(li_idx) + "-")
	sc.concat(is_string)
Next
ls_data = sc.value()
Read more

Sorting a string array


I had a need to sort a string array and I found some code on Real Gagnon’s website that sorted numbers by creating a DataStore/DataWindow on the fly and used that to sort. Someone added a comment that for strings you need to define the column as char to avoid errors. I improved the code by adding a loop to determine the longest string in the array and using that when defining the DataWindow source.

 

public function boolean of_sortarray (ref string as_array[], string as_order);// —————————————————————————–

// SCRIPT:     of_SortArray

//

// PURPOSE:    This function sorts the passed array using a DataStore created

// on-the-fly.

//

// This is based on code from Real Gagnon:

// http://www.rgagnon.com/pbdetails/pb-0114.html

//

// ARGUMENTS:  as_array – Array of values to sort

// as_order – The sort order:

//

// Order value Resulting sort order

// ———————— —————————

// a, asc, ascending, ai, i Case-insensitive ascending

// d, desc, descending, di Case-insensitive descending

// as, s Case-sensitive ascending

// ds Case-sensitive descending

//

// DATE        PROG/ID DESCRIPTION OF CHANGE / REASON

// ———-  ——– —————————————————–

// 09/27/2016 RolandS Initial Coding

// —————————————————————————–

 

Read more

How to make a MessageBox automatically timeout


I was wondering if it was possible to have a MessageBox that could automatically close after a set period of time so I did some searching and found that you can!

 

In Windows XP, Microsoft added a function MessageBoxTimeout but didn’t document it. The normal MessageBox function was changed to call MessageBoxTimeout passing the maximum value for the timeout. The maximum timeout value equates to about 49 days.

Read more

How to capture error messages from an ActiveX control


Normally when you use OLEObject to connect to an ActiveX control and encounter an error, you will get the generic run time error ‘R0035 – Application terminated. Error calling external object function xxx’.

 

I have run across a very simple way to capture the actual error code and message generated by the ActiveX control.

 

First, create a new Standard Class object and select oleobject for the type.

 

Next add the following instance variables:

 

ULong ErrorCode

String ErrorText

 

Then add this code to the externalexception event:

 

ErrorCode = ResultCode

ErrorText = Description

 

Finally save the object as n_oleobject.

 

Read more

Calling .Net Assemblies from PowerBuilder Win32 via PowerShell


Recently someone asked me how they could get the output from PBDOM used from a PowerBuilder Classic Win32 application formatted with white space as PBDOM doesn’t include it.  I gave them a number of options, particularly MSXML through OLE Automation or using a .Net class like XmlTextWriter.  Normally if you were going to try to access a .Net assembly from a PowerBuilder Classic Win32 application, you would do it via a COM Callable Wrapper.  However, for something this simple I thought there had to be a more lightweight way to accomplish it.  One particular lighterweight way that occurred to be would be to have the application launch a Windows PowerShell script that would then use the .Net class in question.  We’re going to look at an example of how that’s done.

The first thing we’ll need is the PowerShell script to do the work. This is what I came up with (referenced as prettyprint.ps1 in the later code):

param( [string]$filein, [string]$fileout ) [void][System.Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq") [System.Xml.Linq.XDocument]::Load($filein).Save($fileout) # If running in the console, wait for input before closing. if ($Host.Name -eq "ConsoleHost") { Write-Host "Press any key to continue..." $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") > $null }

The script declares a couple of parameters (the input xml file and the output xml file).  It then loads the System.Xml.Linq .Net assembly via reflection.  Finally, we load the file and then write it back out again with white space.  The last few lines are just for debugging from a command line prompt, as it displays a “Press any key to continue…” prompt before closing the PowerShell process window.

To test it through a batch file, I used this:

@ECHO OFF SET ThisScriptsDirectory=%~dp0 SET PowerShellScriptPath=%ThisScriptsDirectory%prettyprint.ps1 SET SourceFile=%ThisScriptsDirectory%config.xml SET DestFile=%ThisScriptsDirectory%.config.new.xml %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%' -filein '%SourceFile%' -fileout '%DestFile%'"; pause

The assumption here is that the batch file, the PowerShell script and the input xml file are all in the same directory.  I’ve got a pause statement in this script, so you actually get two “Press any key to continue…” prompts.  If it works properly, that’s all you should see.  Otherwise you should see the error message from PowerShell or the batch file.

Read more

Find Articles by Tag

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