Creating ActiveX controls with Delphi
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
Many hardcore Delphi developers never tire of arguing the merits of VCL components over ActiveX controls. Regardless of your own view, one thing's for sure; you shouldn't allow your preferences to limit your market share. Consider offering your customers both VCL and ActiveX versions.
In his book, Delphi COM Programming (published by MacMillan Technical Publishing), Eric Harmon explains why you should consider converting your VCL to ActiveX, along with clear step-by-step instructions on how to accomplish the conversion.
Creating ActiveX Controls
In this section, I'll show you how to create an ActiveX control from an existing Delphi component. In Delphi, you take an existing visual control (derived from TWinControl) and turn it into an ActiveX control. This means that you can write and test a VCL component completely in Delphi before taking the plunge and creating the ActiveX control.
Reasons to Create ActiveX Controls
With all the capability of the VCL, why should you create an ActiveX control? For one very good reason: You want your control to be usable by all the developers out there who aren't using Delphi. By far, the largest market for ActiveX controls is the Visual Basic market.
Converting a VCL Component to an ActiveX Control
For purposes of illustration, let's convert the TCheckListBox component into an ActiveXcontrol. To do this, execute the following steps:
From the Delphi main menu, select File, New. The Object Repository is displayed.
On the ActiveX page, select ActiveX Library and click OK.
Select File, New again, and select the ActiveX Control icon from the menu.
ActiveX page of the Object Repository. The ActiveX Control Wizard appears.
From the VCL Class Name combo box, select the VCL component to convert to an ActiveX control.
When you select TCheckListBox in the combo box, the ActiveX Control Wizard automatically generates default values for the ActiveX control name, Implementation unit, Project name, and Threading model.
You should always leave the threading model set to tmApartment, as it is required for ActiveX controls used by Visual Basic.
To learn more, check out the book Delphi COM Programming, published by MacMillan Technical Publishing and available from New Riders.