Welcome to the Appeon Community!

Learn, share knowledge, and get help.

 

FEATURED BLOGS

NEW ARTICLES

Free My GUI! - Multi-Threading in PowerBuilder

In this follow-up to the article titled “’Haunted Apps’ – How to Avoid Ghost (Unresponsive) Windows”, you’ll learn about the multi-threading capabilities available to PowerBuilder applications and how multi-thread...

Read more

How to create an application from object source code files using PowerBuild...

PowerBuilder can create an entire application from the object source files stored in a source code control system without relying on existing PBLs. This has been public knowledge for years, but since I cannot find the article...

Read more

Defining a PostgreSQL Database Profile in PB2019R3

PB2019R3PostgreSQL v12 database Summary:   Ensure that the database properties are defined correctly for the PostgreSQL database in the DB Painter.    If those properties are not defined correctly, the PB2019R3 IDE...

Read more

Create Multiple DSNs from a single PostgreSQL Driver

FYI - Summary:   You can create multiple databases from a single PostgreSQL driver. Details:PowerBuilder R2019R3 PostgreSQL 12Windows 10 These instructions assume that at least one PostgreSQL driver has been successfull...

Read more

Generating a QR code using QRCoder

QRCoder is an open source .Net assembly for creating QR Codes.  What we're going to do is wrap that with an assembly in SnapDevelop we can use from PowerBuilder.  First thing we need to do is create a .Net standard Class...

Read more

Detecting a smart card insertion/removal from PowerBuilder

This is a follow up article to an earlier article I wrote called Communication with a smart card from PowerBuilder. In that article I showed how to interact with a smart card once it was inserted in the reader.  In this...

Read more

FEATURED ARTICLES

REST Enhancements in PowerBuilder 2019

REST support was added to PowerBuilder in 2017 R2 and enhanced in 2017 R3.  PowerBuilder 2019 contains additional significant enhancements to REST support, including the following: RetrieveOne method – For REST methods...

Read more

Merging PDF files using PoDoFo

One PDF capability that still hasn't been introduced as a native feature in PowerBuilder is the ability to merge PDF files. We're going to look at how we can easily add that capability using the open source (LGPL) PoDoFo...

Read more

Quick start for contributing to Open Source PFC

Given that not everyone is fluent in using Git and or Github (where the Open Source PFC is hosted now), I put together a quick introduction in how to get started.  The video below walks through the steps, which in summar...

Read more

A Simple Methodology for Complex Resizing Scenarios Using the PFC

The Resize service included in the PowerBuilder Foundation Class (PFC) framework is a powerful, yet easy-to-use tool in the developer’s toolbox. Due to several factors, however, many PB developers struggle to make the Resi...

Read more

Applying a New UI Theme to Your Application

This tutorial is an update to the 2019 tutorial. If you have zero experience with the UI Theme feature, please first follow our Quick Start tutorial. If you are ready to gain a comprehensive understanding of this feature...

Read more

Implementing OAuth 2.0 Authorization with PowerBuilder 2019 R2

Introduction PowerBuilder supports getting secured data from the OAuth 2.0 authorization server. The Bearer access token is supported, and the following grant types are supported: Authorization Code Implicit Flow Client...

Read more

To address those issues, a new column type, called the TableBlob column, has been added to the WPF DataWindow. Like the Database Binary / Text Large Object column, there is a separate dialog used to associate the column to a particular table and blob column in that table and specify the where clause (see Figure 2). However, with the TableBlob column, the only other thing you have to specify is the type of data that will be presented. Current choices are limited to Rich Text, Image, and XPS Document.

Let's see how it works with some images. I created the following table in SQL Anywhere to hold the data:

CREATE TABLE "dba"."images" (
"image" long binary DEFAULT NULL,
"id" integer DEFAULT autoincrement,
"pathname" varchar(128) DEFAULT NULL) ;

The pathname isn't necessary for the new column type to work; it was primarily added because of the way PowerBuilder interacts with tables that have autoincrement primary keys. I have to store something in the table when I originally create a record. It can't be the blob, because we'll be loading that after the record is created using an UPDATEBLOB statement. And it can't be the autoincrement column, because that's the column I want the database assigning and then PowerBuilder pulling back for the newly created row. I added the pathname to have some updateable field for the initial row insert.

To load images into that table, I created a DataWindow for it and then used the script in Listing 1 to allow the end user to load the image files.  I then created a WPF DataWindow and dropped a TableBlob column onto it, providing these values in the dialog:

Table:    dbo.images
Large Binary/Text Columns:     image
File Type:     Image
Key Clause:    id = :id

I created a WPF Window to host it, scripted up the connection to the database and the retrieve, and the result is shown in Figure 3 (provided you're a Braveheart fan).

One consequence of using the TableBlob column to render the data is that double-clicking on the image display won't do anything by default. You would have to add code to respond to that event. For a Database Binary / Text Large Object column, double-clicking on the data would cause PowerBuilder to launch the associated application and pass the data to it. You could also accomplish the same thing in code using the DataWindow OLEActivate method. I can think of one time when I found that even remotely useful, and most of the time I was trying to find a way to prevent that behavior. The TableBlob column gives me the capability to display the data more elegantly, and yet have much better control over when I want the user to be able to interact with the data outside of the application.

If you do want the user to be able to work with the data outside of your application, you could accomplish that by writing out the data to a local file (the inverse of Listing 1) and then passing that to the target application via command-line arguments (the lpParameters attribute of the SHELLEXECUTEINFO structure passed to the Windows API ShellExecuteEx command to launch the application) or through OLE Automation.

What gets a bit more complex would be updating the data if the user modified it. With the Database Binary / Text Large Object column, that happened pretty much automatically when the user closed the launched application (providing that your application and the window that launched the OLE application was still available). The OLE application returned the updated information back to the Database Binary / Text Large Object column and then you could decide what action to take regarding an update of the database.

One approach would be to have your window remember the timestamp on the file and check it before allowing the window to close to see if it's been updated. If you used the ShellExecuteEx method to launch the target application, you could also use the hProcess attribute of the SHELLEXECUTEINFO structure to monitor the target application to see when the user closes it and do your update check there. (You would need to set the SEE_MASK_NOCLOSEPROCESS flag on the fMask attribute to let ShellExecuteEx know you wanted the handle of the target application back.) Perhaps the best method might be to simply have the user manually upload the modified file, much the way it was originally loaded.

Updating the data, at least in my experience, is more the exception than the rule. The bottom line is that the TableBlob column gives us a much better way to display image and rich text data in our applications (I don't have much use for XPS). Right now it's limited to WPF applications, but Sybase has indicated that the TableBlob column type will be added to the DataWindow object for PowerBuilder Classic in a future release.

 

--This article was originally published on PBDJ.

Comments (0)

There are no comments posted here yet