PowerBuilder
Here are some tricks and source codes for PowerBuilder.
Any remark, suggestion, question is welcome. Feel free to drop me a mail.
You can take a look to my collection of PB related links (on Del.icio.us)
PBNI Extensions
PBNI = PowerBuilder Native Interface, it's a SDK provided by Sybase that let you create some extensions for PB in C++ (with Microsoft Visual Studio)
PbniRegex + PbRegexCoach
As an attempt to fix the performance issue of unvo_regexp I've written a PBNI extension that can execute perl-compatible regexps (with the PCRE engine). The extension also provides a replaceall global function.
The extension is written with the SDK given with PB and starting from samples found on Codexchange.
Key features of uo_regex
object:
- perl regex syntax (you can for example use capturing groups - PCRE stands for Perl Compatible Regular Expression)
- replace method on the regex matches that can reuse the matched groups (syntax:
\1 \2 \n
)
- provides a
FastReplaceAll()
global function that you can call without the need to instanciate uo_regex; even if that function is implemented in C++, it is far more fast than a pbscript equivalent
To test the extension, I have also made PbRegexCoach (kinda remake of The Regex Coach) :
That application also reuses several components written by Nicolas Georges : auto-resizer, horizontal & vertical splitters derived from Roland Smith ones. He has also published an example of pbniregex usage.
Extension pbniregex.zip (sources included) + PbRegexCoach - Last update: Saturday April 1 2017.
ChangeLog
2017-03-31 - version 1.3.2 (copyright update)
- added the generation of pbx for PB125
- added the demo application for PB125
2013-11-20 - Version 1.3.1
- support for named capturing group, including in replace strings
- bugfixed the empty pattern replacing that caused infinite loop
- IMPORTANT : until now the lib PCRE was compiled with default newline=LF
that is causing unexpected behavior when matching / replacing
text near end of line.
NOW it compiled with default newline=CRLF.
To get back the old behavior, you can add the option (*LF)
at the beginning of your patterns.
2013-07-01 - Version 1.3
- upgraded the underlying PCRE to 8.33 !!!
- addition of jit-enabled regexps (available in PCRE since v.8.20)
- replaced the Hello() method by GetVersion() and GetVersionFull()
- fixed some memory leaks when calling Study() some multiple times
- code cleanup
2011-07-04 - Added the PB12 version
2011-06-28 - PB9 backport complete.
Support for escaped backslashes in Replace(), now you can use strings like
'\\1' for inserting '\1' into replaced text. Added the possibility to get the
whole match with '\0'.
2011-06-21 - Started the PB9 backport, exported the source code separately into folder
for each PB version 9,10,11.5
2011-06-18 - the pbx/pbd files zere backported to PB10.5 and PB10.0 (actually 10.2)
the pbx, pbd and sample files (pbregexcoach.exe, pbl's) are named like the
PB development files : pbniregex115, pbregexcoach105, worksp100.pbw...
2011-02-14 - Upgrade of the splitters (various bugfixes and enhancements)
Export of the components source code (into pb_src folder) to help backporting
2009-09-09 - Project upgraded to PB 11.5
2009-06-26 - Added the GetLastError() method to get... err... the last error :)
2009-04-27 - PBX recompiled with PB 10.5.2.7826
2009-04-01 - I noticed that the utf-8 mode was buggy : when strings contained some
extended chars, both length & positions functions returned wrong values and
the returned strings were not correctly translated back into PB internal
utf-16. Reworked the internal string handling to always work in utf-8,
setutf8() does nothing and isutf8() always returns true.
The initialize() method does not fail anymore if the pattern is null (it used
to return a PBX_E_INVOKE_WRONG_NUM_ARGS status in that case)
I reworked the UI layout a bit with Nicolas Georges. The close menu problem
is solved.
The license conditions were updated to adopt the formal MIT license.
2009-03-16 - Minor refactor of the GUI + added a mini-help TODO : there is a little GUI
problem : the close button and system menu have disappeared you have to quit
with the File / Quit menu item
2009-03-11 - Bugfix in Replace() : broken by last modification to get the capturing groups
count, was replacing only the first occurence
Bugfix 2 : trying to replace an empty string by an empty string got endless
loop :S
Nicolas Georges refactored the UI to use a splitter and added a live-update
of the results. There is also a unit-test functionnality now.
2009-02-25 - Bugfix in Replace() : use the number of capturing groups from the pattern
instead of the number of the matched groups for the expansion of the \nn
items. E.g: Replace() returned \1 instead of an empty string when a pattern
with a capturing group matched nothing.
2009-02-09 - fixaround with search() when a match has null length
I noticed that the HeapAlloc calls *should* be surrounded by try/catch ;)
2008-11-26 - added the getpattern() method
2008-11-14 - fixed the correct handling of the option multiline
added the options and methods to handle dot-match-newlines, ungreedy and
extended syntax minor layout changes in regex coach
2008-11-13 - bugfix : crashing during replace() when a group matches nothing is bad :o)
2008-11-11 - rewrote the vector allocation for matches & groups with dynamic allocation
added the study() method
2008-11-05 - first public release
2008-09-08 - creation of PbRegexCoach as a test tool for PbniRegex
2008-09-01 - start of the project
PbniHash
The hashtable (also : dictionary, associative array) is a useful data structure, alas it is not available natively in Powerbuilder.
The libhashish opensource lib implements several hashing algorithms under GNU/Linux. I have ported that lib to Windows thanks to MinGW (Nicolas Georges has disabled the tree hashing algorithm for allowing us to reuse libhashish under the BSD licence) and I have wrote a pbni extension that provides hashtables to Powerscript.
The libhashish has many features but my wrapper is limitted to the bare features :
- the keys are strings
- the values are from any type, thus any object type can be stored into the table
- add or delete an item by its key
- replace an existing item
- the items count can be obtained
- the keys can be returned into an array, thus you can crawl the whole table, but the order is not predefined : it depends on the hashing algorithm
- the table can be purged
Extension pbnihash.zip (sources included) + PB sample - Last update: Tuesday July 17 2018.
ChangeLog
2018-07-17 - Resurrected the 10.5 version
2017-04-10 - Reorganized the project for PB115 in order to produce other versions
the .pbx is now pbnihash115.pbx
2012-05-09 - Fix of_getkeys / of_geteach by reusing any array from argument
2012-04-11 - Use in memory buffer rather than temporary files
2012-01-05 - Use Shiny lib to profile code
improve pbserializer by using FILE* rather than HANDLE for file access
2012-01-02 - Fixe ReleaseString memory leaks
Pre-allocate pbarray before to fill'them'up
Added of_getvalues, of_geteach, of_serialize, of_unserialize
Add Display_hash button and function to demo project
Allow null values as data
2011-07-03 - Added a script to help the packaging and distrbution
2009-07-11 - first public release
2009-07-02 - bug fixed GetKeys() - the returned array is from correct type so no more
crash while copying the array
2009-06-05 - Nicolas Georges has recompiled libhashish without tree hashing algorithm to
let us use the BSD license
2008-09-01 - start of the project
PbniList
The linked list is another missing feature from PowerBuilder. Since the pbni sdk is in C++ I have used the STL to implement a list (uo_list
) and a vector (uo_vector
).
My own lists and vectors have the following interesting features:
- you can add (and remove) items at the beginning, end or at any given position
- the list and vector have an integrated iterator, thus you can easily walk them in any direction
- the both objects are sortable (you pass an object to the
sort()
method that must implement a function int list_compare(any, any)
that can compare 2 elements at a time from the list / vector
Extension pbnilist.zip (sources included) + PB sample - Last update: Tuesday April 11 2017.
ChangeLog
2017-03-31 - version 0.4.3 (copyright update)
- Added the demo application for PB125
2017-01-25 - fixed the settings for the PB12 version
- Added the PB125 and PB126 pbx
2015-03-26 - renamed insert() to inserthere()
2011-07-04 - Added the PB12 version
2011-07-03 - added a script to help the packaging and distribution
2011-06-28 - Backported the extension and the demo application to PB9,10,10.5
2011-02-04 - patch SetCorrectPBValue method to allow Object, Enum, Array and null values
(geni)
2010-11-10 - added the comparison function name to sort() method arguments : now we can
use any comparison function, as long as its signature is "int func(any a, any b)"
the returned value is like for the classical strcmp() : -1 if a<b, 0 if a=b, 1 if a>b
2010-05-01 - First public release
2010-02-16 - implemented the sort() methods for both list and vector
2010-02-12 - added the vector implementation + benchmarks
2010-02-02 - start of the project
PbniCW - Cool Wrappers
These are several wrappers that could not be included in former extensions.
List of features :
- Read access to VersionInfo resources of .exe and .dll :
GetVersionInfoString()
, GetVersionInfoFullString()
, GetVersionInfoFixed()
CWGetField()
/ CWSetField()
to get / set any property of userobjects and UI controls
RetrieveVarArgs()
let you perform a retrieve()
on a Datawindow or Datastore by giving the retrival arguments in an array of anys (useful to write dynamic code with a DW that you change the dataobject)
- Logical Functions on unsigned longs :
BitwiseOr()
, BitwiseXor()
, BitwiseAnd()
, BitwiseNot()
, BitwiseLeftShift()
, BitwiseRightShift()
- Conversions ulong -> string :
ToHexString()
and ToOctalString()
- Adaptive Server Anywhere Specific : object uo_transaction that let you receive notifications from the database, for example while running a stored procedure. If you want to recompile that extension, you need to have the ASA SDK.
Known bugs
CWGetField()
on non-existing property makes PB crash
GetVersionInfoxxx()
on application itself makes PB crash
Extension pbnicw.zip (sources included) + PB sample - Last update: Monday 17 May 2010.
ChangeLog
2010-05-17 - First public release
2009-09-25 - Bitwise manipulation functions, ToHEx(), ToOct()
added a #define for USE_ASA_ODBC
Bugfix RetrieveVaArgs when no arg in array + test from pbnicw.pbl
2009-09-24 - Message notification handler for asaodbc by Nicolas
2009-08-29 - Upgraded to PB 11.5.0.3127, RetrieveVaArgs by Nicolas Georges
2009-04-27 - Upgraded to PB 10.5.2.7826
2008-12-17 - Access to simplified version infos
2008-09-18 - start of the project, access to FixedVersionInfo
Other components - userobjects
unvo_regexp
unvo_regexp is a native userobject that remaps vbscript.regex OLE object (author : Nicolas Georges). The supported syntax is listed in the instance variables view (it's the regular vbscript.regex syntax).
That userobject is quite useful for casual usage. But the performance is not that good for example if you instanciate the object in loops due to the connection to the OLE object in the constructor event.
splitters
u_scilexer
Roland Smith has published in
Topwiz Software a PB warpper for the
Scintilla editor. With the help of Nicolas Georges, I have added the support for margin icons, code completion and others features. Here is my implementation :
u_scilexer.sru (you need also the scintilla dll renamed to "scilexer.dll").
Last update: Sunday October 30 2011.
n_zlib
n_zlib.sru: another component from Roland Smith to wrap the
zlib in PB. I have added the support for the gzipped streams to Roland's implementation.
Last update: Wednesday June 11 2014.
nv_codec_base64
nv_codec_base64.sru is a pbscript implementation of a base64 codec (for a decent performance there is a dependency with pbnicw for the bitwise operations). The encoding is quite slow though for big amounts of data, do not use it on mega bytes...
Complementary tools
libexport
libexport is a little tool I wrote to test the export of pbl objects in PBScript.
You can export the whole pbl or just a selection. The objects are exported in UTF-16le format with their library comments.
libexport.zip - Last update: Friday June 10 2016
FILL ME: script perl check pbg
FILL ME: script perl dw
pbdumper
pbdumper is an experimental tool that can export the whole content of a PB library (pbl / pbd) or PB dll or executable. This tool was successfully tested with libs produced by PB from the version 5 to 10.5 and should work also with PB 11 / PB 12 if the pbl structure did not changed. I have used that tool to get some resources from applications that were written by my company and sources eventually lost.
It is written in C99 and built with MinGW. This tool could not have existed without the precious infos from the PBL file format released by Arnd Schmidt. He also made some tools to explore the PB libraries.
Todo :
pbdumper - Last update: Tuesday March 13 2012
ChangeLog
2012-03-13 - (0.9.9) - bugfix newline export in source files headers
- bugfix library name display in list mode
- do not try to process directories (problem seen when processing *.pbl
and there is some lib.pbl-dump folders)
- refactor of the source code export
- added the --scc info to show the source control attributes of library entries
2012-02-21 - (0.9.8) - added the support for library entries with a path in the name
2012-01-12 - (0.9.7) - added the --debug to filter debug output + reworked the listing mode
2012-01-10 - (0.9.6) - added the --name for wildcard matching on objects names
2012-01-09 - (0.9.5) - fixed a stupid bug in the NOD* tree parsing
- added the --source-only option
- added the --list option
2011-11-05 - (0.9.4) - rewrote the command line parsing with getopt
- added a simulation parameter (--dry-run)
2011-10-26 - (0.9.3) - bugfixed the dump of ENT* blocks
- code rewritten in C99 instead of C++
- filter the output with a verbose switch
- can create a folder to dump the objects in
2009-10-26 - (0.9.2) improved the export of the pbscript source files
2008-10-22 - (0.9) initial release
2009-10-18 - proper export of the source files with header and comments
2008-10-24 - Initial prototype
Links
- Nicolas Georges : creator of the Datawindow Debug Machine, auto-resizers and Embedding Perl project (that make possible to script PB applications with perl)
- Roland Smith : provides many integration modules for tools like Scintilla, or components like splitters...
- PowerToTheBuilder : provides several components (commercial) to give a fresh look to your PB applications : dockable windows, tab controls, auto filter for datawindow...