Using the Chilkat ActiveX in PowerBuilder
connect an OLEObject to a Chilkat class with ConnectToNewObject, then call it from
PowerScript
Windows · PowerBuilder (32-bit IDE) · 32-bit and 64-bit applications · Chilkat ActiveX v11
PowerBuilder uses COM automation objects through the OLEObject class. You create an OLEObject,
connect it to a Chilkat class such as Chilkat.Http, Chilkat.JsonObject, or
Chilkat.Crypt2, and call its methods and properties from PowerScript. That gives a PowerBuilder application
HTTP/REST, email, FTP/SFTP, SSH, Zip, PDF, encryption, digital signatures, JSON, XML, and the rest of the Chilkat API.
The 60-second version
- Install the 32-bit Chilkat ActiveX on your development computer (the PowerBuilder IDE is 32-bit), plus the 64-bit one if you build 64-bit applications.
- Create an object:
loo_Http = CREATE OLEObject, thenloo_Http.ConnectToNewObject("Chilkat.Http"). - Paste the first script into a button's
clickedevent and run. - When you deploy, install the Chilkat ActiveX that matches your application's bitness.
On this page: Install First script JSON into a list Passing objects PowerBuilder tips Deploying Troubleshooting
Setup
Install the Chilkat ActiveX
The Chilkat ActiveX DLL must have the same bitness as the process that loads it:
| Purpose | Chilkat ActiveX needed |
|---|---|
| Running and debugging in the PowerBuilder IDE (32-bit) | 32-bit |
| Running a 32-bit application | 32-bit |
| Running a 64-bit application, including running one from the IDE in PowerBuilder 2022 and later | 64-bit |
Installing both on your development computer covers every case; they coexist without problems. Your PowerScript is the same for 32-bit and 64-bit builds.
Per-machine installers register Chilkat for every user of the computer and need administrator rights; per-user
installers register it only for the current user. Use per-machine if the IDE or the application runs as administrator,
because an elevated process doesn't use per-user registrations. ZIP downloads with a register.bat script are on
the ActiveX download page. Keep the DLL on a local drive. The downloads are the full
version and are fully functional for a 30-day evaluation.
Examples
Your first script: unlock Chilkat and fetch a URL
Chilkat must be unlocked once per process with UnlockBundle, so do it once when the application starts,
for example in the application object's open event. During the 30-day trial any string works; after purchase,
use your license code.
// Application open event: unlock Chilkat once.
OLEObject loo_Glob
integer li_rc
loo_Glob = CREATE OLEObject
li_rc = loo_Glob.ConnectToNewObject("Chilkat.Global")
if li_rc < 0 then
DESTROY loo_Glob
MessageBox("Chilkat", "Chilkat ActiveX is not registered (ConnectToNewObject returned " + string(li_rc) + ").")
return
end if
if loo_Glob.UnlockBundle("Anything for 30-day trial") <> 1 then
MessageBox("Chilkat", string(loo_Glob.LastErrorText))
end if
DESTROY loo_Glob
Then, in a button's clicked event:
OLEObject loo_Http
integer li_rc
string ls_Text
loo_Http = CREATE OLEObject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
DESTROY loo_Http
MessageBox("Chilkat", "ConnectToNewObject failed: " + string(li_rc))
return
end if
ls_Text = loo_Http.QuickGetStr("https://www.chilkatsoft.com/helloworld.txt")
if loo_Http.LastMethodSuccess <> 1 then
MessageBox("Chilkat", string(loo_Http.LastErrorText))
else
MessageBox("Chilkat", ls_Text)
end if
DESTROY loo_Http
A message box shows Hello World!. The ProgID is Chilkat. plus the class name, for example
Chilkat.JsonObject or Chilkat.Crypt2.
Load JSON from a web request into a ListBox
This script downloads a small JSON document, parses it with Chilkat.JsonObject, and adds each member to a
ListBox named lb_1. The same pattern works for any REST API: send the request with Chilkat.Http or
Chilkat.Rest, then read the fields with StringOf, IntOf, and
SizeOfArray.
OLEObject loo_Http, loo_Json
string ls_Json
long ll_i, ll_count
// {"apple":"red", "lime":"green", "banana":"yellow", ...}
loo_Http = CREATE OLEObject
loo_Http.ConnectToNewObject("Chilkat.Http")
ls_Json = loo_Http.QuickGetStr("https://www.chilkatsoft.com/exampledata/sample.json")
if loo_Http.LastMethodSuccess <> 1 then
MessageBox("Chilkat", string(loo_Http.LastErrorText))
DESTROY loo_Http
return
end if
DESTROY loo_Http
loo_Json = CREATE OLEObject
loo_Json.ConnectToNewObject("Chilkat.JsonObject")
if loo_Json.Load(ls_Json) <> 1 then
MessageBox("Chilkat", string(loo_Json.LastErrorText))
DESTROY loo_Json
return
end if
lb_1.Reset()
ll_count = loo_Json.Size
for ll_i = 0 to ll_count - 1
lb_1.AddItem(string(loo_Json.NameAt(ll_i)) + "~t" + string(loo_Json.StringAt(ll_i)))
next
DESTROY loo_Json
For brevity, this script doesn't check ConnectToNewObject's return value; production code should, as in
the first script.
Passing and receiving Chilkat objects
Pass a connected OLEObject directly to a Chilkat method that takes an object:
OLEObject loo_Resp
loo_Resp = CREATE OLEObject
loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpStr("POST", ls_Url, ls_Body, "utf-8", "application/json", loo_Resp)
if li_Success = 1 then
ll_Status = loo_Resp.StatusCode
end if
A method that returns a Chilkat object can be assigned to an OLEObject variable. Check
LastMethodSuccess before using it, because a failed call returns a null object.
Things to know when calling Chilkat from PowerBuilder
Chilkat returns 1 or 0, not a PowerBuilder boolean. Chilkat ActiveX methods that report success, and properties
such as LastMethodSuccess, return a long: 1 for success and 0 for
failure. Store the result in a long or integer and compare with 1; don't compare it
with TRUE.
| Topic | What to do |
|---|---|
| Errors | Chilkat doesn't raise PowerBuilder errors for ordinary failures. Check the return value (or
LastMethodSuccess for methods that return a string or object) and show LastErrorText, which
explains exactly what went wrong. |
| Late binding | Calls on an OLEObject aren't checked when you compile. A misspelled method or
property compiles cleanly and fails at run time. Wrap Chilkat code in TRY … CATCH (OLERuntimeError e)
if you want to handle that without the application's SystemError event. |
| Return types | Results from an OLEObject are Any values. Assign them to typed
variables, and use string() when you concatenate them, as the examples do. |
| Object lifetime | DESTROY each OLEObject when you're finished with it, which also
releases the Chilkat object. Do this especially for connections (Chilkat.Ssh, Chilkat.Ftp2, and
so on) and inside loops. |
| Long operations | The window doesn't repaint while a Chilkat call runs. Set timeouts such as
ConnectTimeout and ReadTimeout where a class has them. |
| Chilkat v9.5 code | v11 ProgIDs are Chilkat.Http, Chilkat.Global, and so on. Older
v9.5 code uses Chilkat_9_5_0.Http. Both versions can be installed side by side; see
Chilkat ActiveX v11 and v9.5 on the same computer. |
Deploying a PowerBuilder application
Your application finds the Chilkat ActiveX through the Windows registry; it isn't part of the PowerBuilder runtime files. On each computer where the application runs:
- Install and register the Chilkat ActiveX with the same bitness as your compiled application: 32-bit for a 32-bit build, 64-bit for a 64-bit build. Running Chilkat's per-machine MSI from your setup is the simplest way.
- If your installer registers the DLL itself, use
regsvr32for the right bitness; the ActiveX DLL Registration Tutorial explains the details. - Install the DLL to a local folder and don't move it after registering.
Troubleshooting
| Message | Cause and fix |
|---|---|
ConnectToNewObject returns -2 (class name not found) or -3 (object could not
be created) |
The Chilkat ActiveX isn't registered for this process's bitness: the 32-bit ActiveX for the IDE and 32-bit builds, the
64-bit ActiveX for 64-bit builds. It may also be registered per-user while the process runs elevated or as another account.
Install the matching MSI, and check the ProgID spelling (Chilkat.Http). |
| Error calling external object function … Error accessing external object property … |
The method or property name is misspelled, or the installed Chilkat version is older than the one the code was written for. Check the name in the reference documentation. |
| The application works in the IDE but not as a 64-bit EXE | Only the 32-bit ActiveX is installed. Install the 64-bit ActiveX on the computer running the 64-bit EXE. |
| A Chilkat method returns 0 or an empty string | The operation itself failed (a network error, a bad password, an invalid file path, and so on). Show
LastErrorText; it names the cause. |
Next Steps
- 📖 Chilkat PowerBuilder Reference Documentation — every class, method, and property
- 💻 Chilkat PowerBuilder examples — thousands of ready-to-run examples
- 📦 Chilkat ActiveX downloads (MSI installers and ZIP files)
- ✉ Contact Chilkat support
PowerBuilder is a trademark of its respective owner.