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.

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:

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...

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


Press the Install button.

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.

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

Using the control
This component can then be dropped on a form:

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

It can be run:

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.
|