Elements of an ActiveX Control

From RAD Studio
Jump to: navigation, search

Go Up to Using ActiveX Controls Index


An ActiveX control involves many elements which each perform a specific function. The elements include a VCL control, a corresponding COM object wrapper that exposes properties, methods, and events, and one or more associated type libraries.

VCL control

The underlying implementation of an ActiveX control in Delphi is a VCL control. When you create an ActiveX control, you must first design or choose the VCL control from which you will make your ActiveX control.

The underlying VCL control must be a descendant of TWinControl, because it must have a window that can be parented by the host application. When you create an Active form, this object is a descendant of Vcl.AxCtrls.TActiveForm.

Note: The ActiveX control wizard lists the available TWinControl descendants from which you can choose to make an ActiveX control. This list does not include all TWinControl descendants, however. Some controls, such as THeaderControl, are registered as incompatible with ActiveX (using the RegisterNonActiveXprocedure procedure) and do not appear in the list.

ActiveX wrapper

The actual COM object is an ActiveX wrapper object for the VCL control. For Active forms, this class is always Vcl.AxCtrls.TActiveFormControl. For other ActiveX controls, it has a name of the form TVCLClassX, where TVCLClass is the name of the VCL control class. Thus, for example, the ActiveX wrapper for TButton would be named TButtonX.

The wrapper class is a descendant of Vcl.AxCtrls.TActiveXControl, which provides support for the ActiveX interfaces. The ActiveX wrapper inherits this support, which allows it to forward Windows messages to the VCL control and parent its window in the host application.

The ActiveX wrapper exposes the VCL control's properties and methods to clients via its default interface. You must implement the wrapper class' properties and methods, delegating method calls to the underlying VCL control. You must also provide the wrapper class with methods that fire the VCL control's events on clients and assign these methods as event handlers on the VCL control.

Type library

You must generate a type library for your ActiveX control that contains the type definitions for the wrapper class, its default interface, and any type definitions that these require. This type information provides a way for your control to advertise its services to host applications. You can view and edit this information using the Type Library editor. Although this information is stored in a separate, binary type library file (.TLB extension), you may also compile it into the ActiveX control DLL as a resource.

Property page

You can optionally give your ActiveX control a property page. The property page allows the user of a host (client) application to view and edit your control's properties. You can group several properties on a page, or use a page to provide a dialog-like interface for a property. For information on how to create property pages, see Creating a Property Page for an ActiveX Control.