t e m p o r a l 
 d o o r w a y 

The Simplest ActiveX Control

 

Introduction

Creating an ActiveX control in BCB is a very simple process - made even easier by starting with creating a conventional VCL component. There is a big advantage to this - you can test and debug almost everything about your ActiveX control before having to add the complexity of type libraries and GUIDs.

Once you have created your VCL component, with all its events and methods, the process can begin.

Create the ActiveX project

Start by picking File | New | Other and then then click the ActiveX tab and double-click the ActiveX Library icon.

New Items Palette

This creates a .dll project that is the core of your control.

Create the ActiveX control from your VCL

Next, picking File | New | Other and then then click the ActiveX tab and double-click the ActiveX Control icon. Then fill out the following dialog:

Active X Control Wizard

The key item is the VCL class name, which you can pick from the names of all of the VCL components in the currently installed packages. For this example, just pick something like TEdit.

At this point, you are ready. Save the project and all of its files. Then build the project.

Register the control's server

Once the project is built, have the control register itself...

Registering Control From Run Window

This is really running the control as an .exe with a special parameter to cause it to put appropriate entries in the Windows Registry.

Import the control to the Component Palette

Importing ActiveX Control From Component Menu

Import Dialog

Press the Install button.

Install Dialog

For this example, we'll install into the default package (dclusr.bpk); however, you could (and should, generally) create a new package for this purpose.

dclusr Package

Next, build and install dclusr. This puts the component on the palette and links it to the ActiveX control, as shown below.

Component On Palette

Using the control

This component can then be dropped on a form:

Component On Form

And it can be seen to be an ActiveX control when you do a View As Text from the form right button menu.

Form As Text

It can be run:

Form Running With Component

Maintaining the control

Of course, you may need to change the control - to add events or methods. Probably the easiest way is to simply change the VCL and regenerate the control into the package. If you use that strategy, first unregister the control using the project menu entry provided for that purpose.

Copyright © 2004 by Mark Cashman (unless otherwise indicated), All Rights Reserved