Using the Chilkat ActiveX in Delphi
import the Chilkat type library once, then use Chilkat classes like any other Delphi component
Windows · Delphi 7 through current RAD Studio · Win32 and Win64 targets · Chilkat ActiveX v11
Delphi has built-in support for COM. You import the Chilkat ActiveX type library once, and Delphi generates a Pascal
unit, Chilkat_TLB.pas, with a wrapper class for every Chilkat class: TChilkatHttp,
TChilkatJsonObject, TChilkatCrypt2, and so on. Your code then creates and calls those classes
directly, with code completion and compile-time checking.
ActiveX or the Chilkat Delphi DLL?
Chilkat offers two products for Delphi. Both contain the same Chilkat functionality.
Chilkat ActiveX This page
- Windows only (Win32 and Win64).
- Works with any Delphi version that can import a type library, including Delphi 7.
- The DLL must be registered on every computer that runs your program.
- A good fit if you already use the ActiveX, or share it with other COM languages.
Chilkat Delphi DLL Often simpler
- Windows, Linux, macOS, iOS, and Android (VCL and FireMonkey).
- No COM and no registration: deploy the Chilkat native library for each target platform with your application.
- Delphi XE through Delphi 13, and Delphi 7–2010 on Windows.
The 60-second version
- Install the 32-bit Chilkat ActiveX on your development computer (plus the 64-bit one if you build Win64 programs or use RAD Studio's 64-bit IDE).
- In Delphi choose , pick Import ActiveX Control (or Import a Type Library), select Chilkat ActiveX, and create the unit.
- Add
Chilkat_TLBto yourusesclause and writehttp := TChilkatHttp.Create(Self); - When you deploy, install and register the Chilkat ActiveX that matches your EXE's bitness.
On this page: Install Import Unlock First program Passing objects Console apps & threads Tips Deploying Troubleshooting
Setup
Install the Chilkat ActiveX
The MSI installers copy the DLL and register it with Windows. Which ones you need depends on what you are doing:
| Purpose | Chilkat ActiveX needed |
|---|---|
| Importing the type library in the Delphi IDE | 32-bit for the usual 32-bit IDE: its Import Component wizard reads only the 32-bit registry, even on 64-bit Windows. RAD Studio 13 also offers a 64-bit IDE with type library and ActiveX support; if you use it, install the 64-bit ActiveX as well. |
| Running and debugging a Win32 program | 32-bit |
| Running and debugging a Win64 program | 64-bit |
Installing both the 32-bit and 64-bit ActiveX on your development computer covers every IDE and target; they coexist
without problems. The generated Chilkat_TLB.pas is the same for Win32 and Win64.
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. 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.
Import the Chilkat type library
In RAD Studio:
- Choose .
- Select Import ActiveX Control (or Import a Type Library; either works) and click Next.
- Select Chilkat ActiveX v11.x.x in the list and click Next. If it isn't listed, the Chilkat ActiveX isn't registered for your IDE (usually the 32-bit one is missing); see step 1 and Troubleshooting.
- Leave Generate Component Wrappers checked, choose a Unit Dir name (for example a
libfolder in your project), and click Next. - Choose Create Unit and click Finish. Delphi writes
Chilkat_TLB.pasand adds it to the project.
In Delphi 7, the equivalent command is ; select Chilkat ActiveX and click Create Unit.
Choosing Install to New Package instead of Create Unit also puts the Chilkat classes on the Tool Palette, so you can drop them on a form and assign event handlers in the Object Inspector. That's optional; most code simply creates the objects at run time.
Keep Chilkat_TLB.pas with your source code. You import once, not on every computer: commit the
generated unit to source control, and other developers can compile without importing it themselves. Re-import after
upgrading Chilkat to pick up new classes, methods, and properties.
Examples
Unlock Chilkat once at startup
Call UnlockBundle once when your program starts; the unlock applies to every Chilkat object in the process
until it exits. During the 30-day trial any string works; after purchase, use your license code.
uses
..., Chilkat_TLB;
procedure TForm1.FormCreate(Sender: TObject);
var
glob: TChilkatGlobal;
begin
glob := TChilkatGlobal.Create(Self);
try
if glob.UnlockBundle('Anything for 30-day trial') <> 1 then
ShowMessage(glob.LastErrorText);
finally
glob.Free;
end;
end;
Your first program: fetch a URL
Put a TButton and a TMemo on the form and use this as the button's OnClick
handler:
procedure TForm1.Button1Click(Sender: TObject);
var
http: TChilkatHttp;
s: WideString;
begin
http := TChilkatHttp.Create(Self);
try
s := http.QuickGetStr('https://www.chilkatsoft.com/helloworld.txt');
if http.LastMethodSuccess <> 1 then
begin
Memo1.Lines.Add(http.LastErrorText);
Exit;
end;
Memo1.Lines.Add(s);
finally
http.Free;
end;
end;
Run it and click the button: the memo shows Hello World!.
Passing one Chilkat object to another
Many Chilkat methods take another Chilkat object as an argument, such as an HttpResponse to receive a
response. The generated method expects the object's COM interface, so pass the wrapper's ControlInterface
property:
procedure TForm1.Button2Click(Sender: TObject);
var
http: TChilkatHttp;
resp: TChilkatHttpResponse;
begin
http := TChilkatHttp.Create(Self);
resp := TChilkatHttpResponse.Create(Self);
try
// POST a JSON body; the server's reply is written into resp.
if http.HttpStr('POST', 'https://httpbin.org/post', '{"name":"value"}',
'utf-8', 'application/json', resp.ControlInterface) <> 1 then
begin
Memo1.Lines.Add(http.LastErrorText);
Exit;
end;
Memo1.Lines.Add('Status: ' + IntToStr(resp.StatusCode));
Memo1.Lines.Add(resp.BodyStr);
finally
resp.Free;
http.Free;
end;
end;
Methods that return a new Chilkat object return its interface (for example IChilkatJsonObject),
which you can use directly; Delphi releases it automatically.
Console applications, services, and threads
The TChilkat… wrapper classes are designed for VCL forms. In console programs, Windows services, and
background threads, use the COM interfaces instead: create objects with CreateComObject and the
CLASS_… constants from Chilkat_TLB. Interfaces are reference-counted, so there is nothing to
free, and objects are passed to methods directly (no ControlInterface).
Every thread that uses COM must call CoInitialize first and CoUninitialize when it's done. VCL
form applications do this for the main thread automatically; console programs and your own threads must do it
themselves:
program ChilkatConsole;
{$APPTYPE CONSOLE}
uses
System.SysUtils, Winapi.ActiveX, System.Win.ComObj, Chilkat_TLB;
var
glob: IChilkatGlobal;
http: IChilkatHttp;
s: WideString;
begin
CoInitialize(nil);
try
glob := CreateComObject(CLASS_ChilkatGlobal) as IChilkatGlobal;
if glob.UnlockBundle('Anything for 30-day trial') <> 1 then
begin
Writeln(glob.LastErrorText);
Exit;
end;
http := CreateComObject(CLASS_ChilkatHttp) as IChilkatHttp;
s := http.QuickGetStr('https://www.chilkatsoft.com/helloworld.txt');
if http.LastMethodSuccess <> 1 then
Writeln(http.LastErrorText)
else
Writeln(s);
finally
// Release all Chilkat interfaces before CoUninitialize.
http := nil;
glob := nil;
CoUninitialize;
end;
end.
In Delphi versions before XE2, the units are named ActiveX and ComObj instead of
Winapi.ActiveX and System.Win.ComObj.
Things to know
| Topic | What to do |
|---|---|
| Success values | Chilkat ActiveX methods that report success, and properties such as
LastMethodSuccess, are Integer: 1 for success and 0 for failure.
Compare with <> 1 or = 0; don't treat them as Boolean. |
| Errors | Chilkat doesn't raise exceptions for ordinary failures. Check the return value (or
LastMethodSuccess for methods that return a string or object) and read LastErrorText, which
explains exactly what went wrong. COM-level problems, such as an unregistered DLL, raise EOleSysError. |
| Strings | Chilkat strings are WideString (Unicode). In Delphi 2009 and later they convert to
and from string automatically. In Delphi 7–2007, string is ANSI, so keep text in
WideString variables to avoid losing non-ANSI characters. |
| Object lifetime | Wrapper objects created with Create(Self) are freed with the form if you don't
free them yourself; try…finally Free releases them as soon as you're done. Interface variables are
released automatically when they go out of scope or are set to nil. |
| Events | The wrapper classes expose Chilkat's progress events (AbortCheck,
PercentDone, ProgressInfo, …) as On… event properties. The exact
handler signatures are declared in Chilkat_TLB.pas; if you installed the classes in a package, the Object
Inspector creates the handlers for you. |
| Long operations | A Chilkat call blocks the thread it runs on, so a long download in a button handler freezes
the form. Set timeouts such as ConnectTimeout and ReadTimeout, or run the work in a background
thread using the interface style shown above. |
| Late binding | CreateOleObject('Chilkat.Http') returns an OleVariant and needs no
imported unit, but gives up code completion and compile-time checking. It's useful for quick scripts; for applications,
use the imported unit. |
| Chilkat v9.5 code | v11 imports as Chilkat_TLB and uses ProgIDs such as
Chilkat.Http. Code written for v9.5 used Chilkat_v9_5_0_TLB and Chilkat_9_5_0.Http-style ProgIDs;
change the uses clause after importing v11. Both versions can be installed side by side; see
Chilkat ActiveX v11 and v9.5 on the same computer. |
Deploying your application
Your EXE does not contain Chilkat. Every computer that runs it needs the Chilkat ActiveX DLL installed and registered, with the same bitness as the EXE: 32-bit for a Win32 build, 64-bit for a Win64 build.
- The simplest option is to run the matching Chilkat per-machine MSI as part of your setup.
- If your own installer copies the DLL, have it register the DLL. Most installer tools can register COM DLLs
(Inno Setup, for example, has a
regserverflag), or runregsvr32 <path-to-Chilkat-DLL>from an elevated command prompt. - Install the DLL on a local drive of the target computer, not a network share.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
| Chilkat ActiveX isn't listed in the Import Component wizard | The Chilkat ActiveX isn't registered for the IDE you're using. The usual 32-bit IDE's wizard reads only the 32-bit
registry, even if the 64-bit ActiveX is installed, so install the 32-bit version (and the 64-bit version too if you use
RAD Studio's 64-bit IDE). Alternatively, run Embarcadero's tlibimp.exe command-line importer on the Chilkat
DLL. |
| EOleSysError: Class not registered | The Chilkat ActiveX with your program's bitness isn't registered on this computer. A Win64 program needs the 64-bit ActiveX even if the 32-bit one is installed. Install or register the matching DLL. |
| EOleSysError: CoInitialize has not been called | A console program, service, or thread used COM without initializing it. Call CoInitialize(nil) at the start
of that thread and CoUninitialize at the end (see Console applications). |
| EOleSysError: Invalid class string | A late-bound CreateOleObject call used a ProgID that isn't registered: a typo, or a v9.5 ProgID
(Chilkat_9_5_0.…) on a computer with only v11 installed. |
| F1026 File not found: 'Chilkat_TLB.dcu' | The generated unit isn't in the project or on the search path. Add Chilkat_TLB.pas to the project, or add
its folder under . |
| E2003 Undeclared identifier: 'TChilkatHttp' | The unit was imported without component wrappers, so it contains only the interfaces. Re-import with Generate
Component Wrappers checked, or use the interface style (IChilkatHttp with CreateComObject). |
| E2003 Undeclared identifier (a Chilkat method or property) | The name is misspelled, or Chilkat_TLB.pas was generated from an older Chilkat version. Re-import after
upgrading. |
| 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 Delphi ActiveX Reference Documentation — every class, method, and property with its Delphi signature
- 💻 Chilkat Delphi ActiveX examples — ready-to-run code for HTTP, email, SFTP, JSON, encryption, and more
- 🏛️ Chilkat Delphi DLL — the non-COM alternative
- 📦 Chilkat ActiveX downloads (MSI installers and ZIP files)
- ✉ Contact Chilkat support
Delphi and RAD Studio are trademarks of Embarcadero Technologies, Inc.