Using the Chilkat ActiveX in Xbase++
link ascom10.lib, create Chilkat objects with CreateObject(), and call them with
: syntax
Windows · Alaska Xbase++ (32-bit) · Chilkat ActiveX v11
Xbase++ uses COM automation objects through its AutomationObject class. CreateObject() returns
an automation object connected to a Chilkat class such as Chilkat.Http, Chilkat.JsonObject, or
Chilkat.Crypt2, and you call its methods and properties like any Xbase++ object. That gives an Xbase++
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, even on 64-bit Windows. Xbase++ programs are 32-bit.
- Add
#pragma library("ascom10.lib")to your source file. - Write
oHttp := CreateObject("Chilkat.Http")and call its methods. - When you distribute your program, install and register the 32-bit Chilkat ActiveX on each computer.
On this page: Install First program Reading JSON Xbase++ tips Deploying Troubleshooting
Setup
Install the 32-bit Chilkat ActiveX
Xbase++ programs run as 32-bit processes, so they can only load the 32-bit Chilkat ActiveX. The 64-bit ActiveX is invisible to them, even on 64-bit Windows.
| Installer | Use it when |
|---|---|
| Per-machine | Recommended. Registers Chilkat for every user of the computer, including programs run as administrator, services, and scheduled tasks. Requires administrator rights to install. |
| Per-user | Registers Chilkat only for the current Windows user and normally needs no administrator rights. Works when the program runs as that user without elevation. |
The ActiveX download page also has ZIP downloads with a register.bat
script that registers the DLL with regsvr32. Keep the DLL on a local drive, not a network share. The downloads
are the full version and are fully functional for a 30-day
evaluation.
Link the COM support library
CreateObject() is part of Xbase++'s COM/ActiveX support, which lives in ascom10.lib. Add this
line near the top of each source file that uses Chilkat:
#pragma library("ascom10.lib")
Examples
Your first program: unlock Chilkat and fetch a URL
Chilkat must be unlocked once per process with UnlockBundle, so call it once when your program starts.
During the 30-day trial any string works; after purchase, use your license code.
#pragma library("ascom10.lib")
PROCEDURE Main
LOCAL oGlob, oHttp, cText
oGlob := CreateObject("Chilkat.Global")
IF oGlob == NIL
? "Chilkat ActiveX is not available:", ComLastMessage()
RETURN
ENDIF
IF oGlob:UnlockBundle("Anything for 30-day trial") <> 1
? oGlob:LastErrorText
oGlob:destroy()
RETURN
ENDIF
oGlob:destroy()
oHttp := CreateObject("Chilkat.Http")
cText := oHttp:QuickGetStr("https://www.chilkatsoft.com/helloworld.txt")
IF oHttp:LastMethodSuccess <> 1
? oHttp:LastErrorText
ELSE
? cText
ENDIF
oHttp:destroy()
WAIT
RETURN
The program prints Hello World!. The ProgID is Chilkat. plus the class name, for example
Chilkat.JsonObject or Chilkat.Crypt2. Properties are read and assigned like instance variables:
oHttp:Accept := "application/json".
Read a JSON response
This procedure downloads a small JSON document, parses it with Chilkat.JsonObject, and prints each member.
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.
PROCEDURE ListFruit
LOCAL oHttp, oJson, cJson, i
// {"apple":"red", "lime":"green", "banana":"yellow", ...}
oHttp := CreateObject("Chilkat.Http")
cJson := oHttp:QuickGetStr("https://www.chilkatsoft.com/exampledata/sample.json")
IF oHttp:LastMethodSuccess <> 1
? oHttp:LastErrorText
oHttp:destroy()
RETURN
ENDIF
oHttp:destroy()
oJson := CreateObject("Chilkat.JsonObject")
IF oJson:Load(cJson) <> 1
? oJson:LastErrorText
ELSE
FOR i := 0 TO oJson:Size - 1
? oJson:NameAt(i), oJson:StringAt(i)
NEXT
ENDIF
oJson:destroy()
RETURN
Things to know when calling Chilkat from Xbase++
Chilkat returns the number 1 or 0, not .T. or .F. Chilkat ActiveX methods that report success, and properties
such as LastMethodSuccess, return a numeric value: 1 for success and 0 for failure.
Compare with a number (IF nSuccess <> 1). Using the result as a logical value, as in
IF !nSuccess, causes a runtime error.
| Topic | What to do |
|---|---|
| Errors | Chilkat doesn't raise Xbase++ 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. |
| Creating objects | CreateObject() returns NIL if the object can't be created.
ComLastError() and ComLastMessage() then report why. |
| Releasing objects | Call :destroy() on each Chilkat object when you're finished with it, as the
examples do. This releases the COM object immediately, which matters for connections (Chilkat.Ssh,
Chilkat.Ftp2, and so on) and for objects created in loops. |
| Passing objects | Pass a Chilkat automation object directly where a method expects one, for example
oHttp:HttpStr("POST", cUrl, cBody, "utf-8", "application/json", oResp) where oResp was created
with CreateObject("Chilkat.HttpResponse"). |
| Non-English text | If characters outside your code page don't come through correctly in strings, have
Chilkat read and write the text through files or Chilkat.StringBuilder/Chilkat.BinData with an
explicit charset such as "utf-8". |
| Long operations | The user interface doesn't respond 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 an Xbase++ program
Your EXE doesn't contain Chilkat; it finds the Chilkat ActiveX through the Windows registry. On each computer where the program runs:
- Install and register the 32-bit Chilkat ActiveX. The simplest way is to run Chilkat's 32-bit per-machine MSI from your setup, or to have your installer copy the DLL and register it.
- If you register the DLL yourself on 64-bit Windows, use the 32-bit
regsvr32:C:\Windows\SysWOW64\regsvr32.exe. The ActiveX DLL Registration Tutorial explains the 32-bit and 64-bit registries. - Install the DLL to a local folder and don't move it after registering, because the registry records its path.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
The linker reports an unresolved external for CreateObject |
ascom10.lib isn't linked. Add #pragma library("ascom10.lib"). |
CreateObject() returns NIL |
The 32-bit Chilkat ActiveX isn't registered on this computer, or it's registered per-user and the program runs elevated
or as another account. Install the 32-bit per-machine MSI, and check the ProgID spelling
(Chilkat.Http). ComLastMessage() shows the Windows error. |
| A runtime error when calling a method or property | The 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. |
| 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 Xbase++ Reference Documentation — every class, method, and property
- 💻 Chilkat Xbase++ examples — thousands of ready-to-run examples
- 📦 Chilkat ActiveX downloads (MSI installers and ZIP files)
- ✉ Contact Chilkat support
Xbase++ is a trademark of Alaska Software.