Chapter 48
Creating an ActiveX control

An ActiveX control is a software component that integrates into and extends the functionality of any host application that supports ActiveX controls, such as C++Builder, Delphi, Visual dBASE, Visual Basic, Internet Explorer, and Netscape Navigator.

For example, Delphi comes with several ActiveX controls, including charting, spreadsheet, and graphics controls. You can add these controls to the component palette in the IDE, and then use them like any standard VCL component, dropping them on forms and setting their properties using the Object Inspector.

An ActiveX control can also be deployed on the Web, allowing it to be referenced in HTML documents and viewed with ActiveX-enabled Web browsers.

This chapter provides an overview of how to create an ActiveX control in the Delphi environment. It is not intended to provide complete implementation details of writing ActiveX control. For that information, refer to your Microsoft Developer's Network (MSDN) documentation or search the Microsoft Web site for ActiveX information.

Overview of ActiveX control creation

Delphi provides two wizards for ActiveX development:

The ActiveX Control wizard generates an implementation unit that descends from two objects, TActiveXControl for the ActiveX control specifics, and the VCL object of the control that you choose to encapsulate. The ActiveForm wizard generates an implementation unit that descends from TActiveXForm.

To create a new ActiveX control, you must perform the following steps:

  1. Design and create the custom VCL control that forms the basis of your ActiveX control.
  2. Use the ActiveX control wizard to create an ActiveX control from a VCL control

    or,

    Use the ActiveForm wizard to create an ActiveX control based on a VCL form for Web deployment.

  3. Use the ActiveX property page wizard to create one or more property pages for the control (optional).
  4. Associate the property page with the ActiveX control (optional).
  5. Register the control.
  6. Test the control with all potential target applications.
  7. Deploy an ActiveX control on the Web.

An ActiveX control consists of the VCL control from which it is built, as well as properties, methods, and events that are listed in the control's type library.

Elements of an ActiveX control

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

VCL control

An ActiveX control in Delphi is simply a VCL control that has been made accessible to applications and objects that support ActiveX controls. When you create an ActiveX control, you must first design or choose the VCL control from which you will make your ActiveX control.

Note: The controls available from the wizard list are controls derived from TWinControl. Some controls, such as EditControl, are registered as a NonActiveX control, therefore, they do not appear in the list.

Type library

A type library contains the type definitions for the control and is created automatically by the ActiveX control wizard. This type information, which provides more details than the interface, provides a way for controls to advertise its services to host applications. When you design your control, type library information is stored in a file with the TLB extension and a corresponding Pascal file containing the Pascal translations. When you build the ActiveX control, the type library information is automatically compiled into the ActiveX control DLL as a resource.

Properties, methods, and events

The properties, events, and methods of the VCL control become those of the ActiveX control.

Property page

The property page allows the user of a control to view and edit its 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 "Enabling simple data binding of ActiveX controls in the Delphi container".

Designing an ActiveX control

When designing an ActiveX control, you start by creating a custom VCL control. This forms the basis of your ActiveX control. For information on this, see "Creating custom components."

When designing ActiveX controls from either existing VCL controls or from new ActiveForms, keep in mind that you are implementing an ActiveX control that will be embedded in another application; this control is not an application in itself.

For this reason, you probably do not want to use elaborate dialog boxes or other major user-interface components. Your goal is typically to make a simple control that works inside of, and follows the rules of the main application.

Whether you create an ActiveX control from a VCL control or ActiveForm depends on whether you already have an existing control that you simply want to encase in an ActiveX control wrapper. In this case, use the ActiveX control wizard as described in"Generating an ActiveX control from a VCL control".

If you are creating a more complete ActiveX application, use the ActiveForm wizard as described in "Generating an ActiveX control based on a VCL form". Typically, you use an ActiveForm to create and supply ActiveX applications for the Web.

The wizards implement all the necessary ActiveX interfaces required using the VCL objects, TActiveXControl or TActiveForm. You need only implement any additional interfaces you may have added to your control.

Once you have generated the control using either wizard, you can modify the control's properties, methods, and events using the Type Library editor.

Generating an ActiveX control from a VCL control

You generate an ActiveX control from a VCL control by using the ActiveX Control wizard. The properties, methods, and events of the VCL control become the properties, methods, and events of the ActiveX control.

For information about creating VCL controls, see "Creating custom components."

The ActiveX control wizard actually puts an ActiveX class wrapper around a VCL control and builds the ActiveX control that contains the object. This ActiveX wrapper exposes the capabilities of the VCL control to other objects and servers.

Before using the ActiveX control wizard, you must select the VCL control from which to build the ActiveX control.

To bring up the ActiveX control wizard,

  1. Choose File|New to open the New Items dialog box.
  2. Select the tab labeled ActiveX.
  3. Double-click the ActiveX Control icon.

In the wizard, specify the following:

VCL ClassName

Choose the VCL control from the drop-down list. For example, to create an ActiveX control that allows client applications to use a TButton object, select TButton.

For ActiveForms, the VCL class name option is dimmed because Active forms are always based on TActiveForm.

New Name

The wizard supplies a default name that clients will use to identify your ActiveX control. Change this name to provide a different OLE class name.

Implementation Unit

The wizard supplies a default name for the unit that contains code to implement the behavior of the ActiveX control. Accept the default or type in a new name.

Project Name

The wizard supplies a default name for the ActiveX library project for your ActiveX control, if no project is currently open. If you have an ActiveX library open, this option is disabled.

Threading Model

Choose the threading model to indicate how client applications can call your control's interface. This is the threading model that you commit to implementing in the control. For more information on threading models, see "Choosing a threading model".

Note: The threading model you choose determines how the object is registered. You must make sure that your object implementation adheres to the model selected.

Specify the following ActiveX control options:

Make Control Licensed

Check this box to enable licensing for the ActiveX controls that you design and distribute (unless the control is distributed free of charge). The wizard generates both a design-time license for designers of the control, and a runtime license for users of the control.

Include Version Information

Check this box to include version information, such as a copyright or a file description, in the ActiveX control. This information can be viewed in a browser. Specify version information by choosing Project|Options and selecting the Version Info page. Click the Help button on this page for information about each setting.

Note: Version information is required for registering a control in Visual Basic 4.0.

Include About Box

When this box is checked, an About box is included in the project. The user of the control can display the About box in a development environment. The About box is a separate form that you can modify. By default, the About box includes the name of the ActiveX control, an image, copyright information, and an OK button.

The wizard generates the following files:

Licensing ActiveX controls

Licensing an ActiveX control consists of providing a license key at design-time and supporting the creation of licenses dynamically, when the control is created at runtime.

To provide design-time licenses, the ActiveX wizard creates a key for the control that is stored in a file with the same name as the project and with the LIC extension. The user of the control must have a copy of the LIC file to open the control in a development environment. Each control in the project that has Make Control Licensed checked will have a separate key entry in the LIC file.

To support the creation of runtime licenses, the license is generated by querying the control for the license (at design time), storing it, and then passing the license to the control when it is created in the context of an EXE. When the runtime license is passed to the control, the design time license is no longer required.

Runtime licenses for the Internet Explorer requires an extra level of indirection because users can view HTML source code for any Web page, and because an ActiveX control is copied to the user's computer before it is displayed. To create runtime licenses for controls used in IE, you must first generate a license package file (LPK file) and embed this file in the HTML page that contains the control.

The LPK file is essentially an array of ActiveX control CLSIDs and license keys.

Note: To generate the LPK file, use the utility, LPK_TOOL.EXE, which you can download from the Microsoft Web site (www.microsoft.com).

To embed the LPK file in a Web page, use the HTML objects, <OBJECT> and <PARAM> as follows:

<OBJECT CLASSID="clsid:6980CB99-f75D-84cf-B254-55CA55A69452">
    <PARAM NAME="LPKPath" VALUE="ctrllic.lpk">
</OBJECT>

The CLSID identifies the object as a license package and PARAM specifies the relative location of the license package file with respect to the HTML page.

When IE tries to display the Web page containing the control, it parses the LPK file, extracts the license key, and if the license key matches the control's license, it renders the control on the page. If more than one LPK is included in a Web page, IE ignores all but the first.

For more information, search for Licensing ActiveX Controls on the Microsoft Web site.

Generating an ActiveX control based on a VCL form

The ActiveForm wizard generates an ActiveX control based on a VCL form which you design when the wizard leaves you in the Form Designer. You can use the ActiveForm to create applications that you can deploy on the Web.

When an ActiveForm is deployed, an HTML page is created to contain the reference to the ActiveForm and specify its location within the page. The ActiveForm is then displayed and run from within a Web browser. Inside the Web browser, the form behaves just like a stand-alone Delphi form. The form may contain any VCL or ActiveX components, including custom-built VCL controls.

To start the ActiveForm wizard,

  1. Choose File|New to open the New Items dialog box.
  2. Select the tab labeled ActiveX.
  3. Double-click the ActiveForm icon.

In the wizard, specify the following:

VCL ClassName

The VCL class name option is dimmed because Active forms are always based on TActiveForm.

New Name

The wizard supplies a default name that clients will use to identify your ActiveX control. Change this name to provide a different OLE class name.

Implementation Unit

The wizard supplies a default name for the unit that contains code to implement the behavior of the ActiveX control. Accept the default or type in a new name.

Project Name

The wizard supplies a default name for the ActiveX library project for your ActiveX control, if no project is currently open. If you have an ActiveX library open, this option is disabled.

Threading Model

Choose the threading model to indicate how client applications can call your control's interface. This is the threading model that you commit to implementing in the control. For more information on threading models, see "Choosing a threading model".

Note: The threading model you choose determines how the object is registered. You must make sure that your object implementation adheres to the model selected.

Specify the following ActiveX control options:

Make Control Licensed

Check this box to enable licensing for the ActiveX controls that you design and distribute (unless the control is distributed free of charge). The wizard generates both a design-time license for designers of the control, and a runtime license for users of the control.

Include Version Information

Check this box to include version information, such as a copyright or a file description, in the ActiveX control. This information can be viewed in a browser. Specify version information by choosing Project|Options and selecting the Version Info page. Click the Help button on this page for information about each setting.

Note: Version information is required for registering a control in Visual Basic 4.0.

Include About Box

When this box is checked, an About box is included in the project. The user of the control can display the About box in a development environment. The About box is a separate form that you can modify. By default, the About box includes the name of the ActiveX control, an image, copyright information, and an OK button.

The wizard generates the following files:

At this point, the wizard adds a blank form to your ActiveX library project. Now you can add controls and design the form as you like.

After you have designed and compiled the ActiveForm project into an ActiveX library (which has the OCX extension), you can deploy the project to your Web server and Delphi will create a test HTML page with a reference to the ActiveForm.

Working with properties, methods, and events in an ActiveX control

The ActiveX Control and ActiveForm wizards generate a type library that defines and implements the properties, methods, and events of the original VCL control or form, with the following exceptions:

Therefore, you may need to add some properties, methods, and events manually.

Note: Since ActiveX controls have a different mechanism for making controls data-aware than a VCL control, the wizards do not convert the properties related to data. You may want to add some of the ActiveX data aware properties to your control as described in "Enabling simple data binding with the type library".

You can add, edit, and remove the properties, methods, and events in an ActiveX control by editing the type library using either of the following ways:

Note: Any changes you make to the type library will be lost if you regenerate the ActiveX control from the original VCL control or form.

Note: Non-published properties that are manually added to the type library will appear in a development environment, but changes made to them will not persist. That is, when the user of the control changes the value of a property, the changes will not be reflected when the control is run. If the source is a VCL object and the property is not already published, you must create a descendant of the VCL object and publish the property in the descendant.

Adding additional properties, methods, and events

You can add additional properties, methods, and events to the control as follows.

  1. Choose Edit|Add To Interface. The ActiveX controls implementation unit must be open and selected for the menu item to be available.

    This brings up the Add to Interface dialog box.

  2. Choose Method or Event from the Interface drop-down list. Next to Properties/Methods or Events is the name of the interface to which the member will be added.
  3. Enter the declaration for the property, method, or event. For example, if you were creating an ActiveX control with the TButton VCL control, you could add the following property:
      property Top:integer;

    If you check the Syntax helper check box, pop-up windows appear as you type, prompting you for what is expected at each point.

  4. Choose OK.

    The declaration is automatically added to the control's implementation unit, type library (TLB) file, and type library unit. The specifics of what Delphi supplies actually depends on whether you have added a property, method, or event.

How Delphi adds properties

Since the interface is a dual interface, the properties are implemented using read and write access methods in the Pascal file (with the PAS extension). When adding a Caption property, the wizard would actually add the following declaration to the implementation unit:

property Caption: Integer read Get_Caption write Set_Caption;

The read and write access method declarations and implementations for the property would be the following:

function Get_Caption: Integer; safecall;
procedure Set_Caption(Value: Integer); safecall;

function TButtonX.Get_Caption: Integer;
begin
  Result := FDelphiControl.Caption;
end;
procedure TButtonX.Set_Caption(Value: Integer);
begin
  FDelphiControl.Caption := Value;
end;

Note: Because the Automation interface methods are declared safecall, you do not have to implement COM exception code for these methods--the Delphi compiler handles this for you by generating code around the body of safecall methods to catch Delphi exceptions and to convert them into COM error info structures and return codes.

The interface implementation methods simply pass through the behavior to the VCL control. In some cases, you may need to add code to convert the COM data types to native Delphi types.

How Delphi adds methods

When you add a method, an empty implementation is added for you to add its functionality. For example, if you added:

procedure Move;

the following declaration and code would be added to the unit:

procedure Move; safecall;

procedure TButtonX.Move;
begin

end;

Note: Because the Automation interface methods are declared safecall, you do not have to implement COM exception code for these methods--the Delphi compiler handles this for you by generating code around the body of safecall methods to catch Delphi exceptions and to convert them into COM error info structures and return codes.

How Delphi adds events

An ActiveX control can fire events to its container. You add events to specify which events can be fired by the control. The following items are created for each event on the control:

Unlike the Automation interface, the events interface is not added to the control's interface list. The control does not receive these events--the container does.

Enabling simple data binding with the type library

With simple data binding, you can bind a property of your ActiveX control to a specific field within a database. You can do so by setting the property's binding flags using the Type Library editor.

This sectiondescribes how to bind data-aware properties in an ActiveX control. For information on binding data-aware properties in a Delphi container, see "Enabling simple data binding of ActiveX controls in the Delphi container".

By marking a property bindable, when a user modifies the property (such as a field in a database), the control notifies the database that the value has changed and requests that the database record be updated. The database then notifies the control whether it succeeded or failed to update the record.

Use the type library to enable simple data binding,

  1. On the toolbar, click the property that you want to bind.
  2. Choose the flags page.
  3. Select the following binding attributes:

    Binding attribute

    Description

    Bindable

    Indicates that the property supports data binding. If marked bindable, the property notifies its container when the property value has changed.

    Request Edit

    Indicates that the property supports the OnRequestEdit notification. This allows the control to ask the container if its value can be edited by the user.

    Display Bindable

    Indicates that the container can show users that this property is bindable.

    Default Bindable

    Indicates the single, bindable property that best represents the object. Properties that have the default bind attribute must also have the bindable attribute. Cannot be specified on more than one property in a dispinterface.

    Immediate Bindable

    Allows individual bindable properties on a form to specify this behavior. When this bit is set, all changes will be notified. The bindable and request edit attribute bits need to be set for this new bit to have an effect.

  4. Click the Refresh button on the toolbar to update the type library.

To test a data-binding control, you must register it first.

For example, to make a TEdit control a data-bound ActiveX control, create the ActiveX control from a TEdit and then change the Text property flags to Bindable, Display Bindable, Default Bindable, and Immediate Bindable. After the control is registered and imported, it can be used to display data.

Enabling simple data binding of ActiveX controls in the Delphi container

After installing a data-aware ActiveX control in the ActiveX tab of the Palette, and placing the control in the form designer, right-click the data-aware ActiveX control to display a list of options. In addition to the basic options, the additional DataBindings item appears.

Note: You must set the data source property to the data source component on the form before invoking the Data Bindings Editor. In doing so, the dialog supplies the Field Name and Property fields from the data source component. The editor lists only those properties from the data source component that can be data-bound properties of the ActiveX control.

To bind a field to a property,

  1. In the ActiveX Data Bindings Editor dialog, select a field and a property name.

    Field Name lists the fields of the database and Property Name lists the ActiveX control properties that can be bound to a database field. The DispID of the property is in parentheses, for example, Value(12).

  2. Click Bind and OK.

Note: If no properties appear in the dialog, the ActiveX control contains no data-aware properties. To enable simple data binding for a property of an ActiveX control, use the type library as described in "Enabling simple data binding with the type library".

The following example walks you through the steps of using a data-aware ActiveX control in the Delphi container. In this example, we use the Microsoft Calendar Control, which is available if you have Microsoft Office 97 installed on your system.

  1. From the Delphi main menu, choose Component|Import ActiveX.
  2. Select a data-aware ActiveX control, such as the Microsoft Calendar control 8.0, change its class name to TCalendarAXControl, and click Install.
  3. In the Install dialog, click OK to add the control to the default user package, which makes the control available on the Palette.
  4. Choose Close All and File|New Application to begin a new application.
  5. From the ActiveX tab, drop a TCalendarAXControl object, which you just added to the Palette, onto the form.
  6. From the Data Access tab, drop a DataSource and Table object onto the form.
  7. Select the DataSource object and set its DataSet property to Table1.
  8. Select the Table object and do the following:

  9. Select the TCalendarAXControl object and set its DataSource property to DataSource1.
  10. Select the TCalendarAXControl object, right-click, and choose Data Bindings to invoke the ActiveX Control Data Bindings Editor.

    Field Name lists all the fields in the active database. Property Name lists those properties of the ActiveX Control that can be bound to a database field. The DispID of the property is in parentheses.

  11. Select the HireDate field and the Value property name, choose Bind, and OK.

    The field name and property are now bound.

  12. From the Data Controls tab, drop a DBGrid object onto the form and set its DataSource property to DataSource1.
  13. From the Data Controls tab, drop a DBNavigator object onto the form and set its DataSource property to DataSource1.
  14. Run the application.
  15. Test the application as follows:

    With the HireDate field displayed in the DBGrid object, navigate through the database using the Navigator object. The dates in the ActiveX control change as you move through the database.

Creating a property page for an ActiveX control

A property page is a dialog box similar to the Delphi Object Inspector in which users can change the properties of an ActiveX control. A property page dialog allows you to group many properties for a control together to be edited at once. Or, you can provide a dialog box for more complex properties.

Typically, users access the property page by right-clicking the ActiveX control and choosing Properties.

The process of creating a property page is similar to creating a form, you

  1. Create a new property page.
  2. Add controls to the property page.
  3. Associate the controls on the property page with the properties of an ActiveX control.
  4. Connect the property page to the ActiveX control.

Note: When adding properties to an ActiveX control or ActiveForm, you must publish the properties that you want to persist. For details see "Exposing properties of an ActiveX control".

Creating a new property page

You use the Property Page wizard to create a new property page.

To create a new property page,

  1. Choose File|New.
  2. Select the ActiveX tab.
  3. Double-click the Property Page icon.

The wizard creates a new form and implementation unit for the property page.

Adding controls to a property page

You must add a control to the property page for each property of the ActiveX control that you want the user to access.

For example, the following illustration shows a property page for setting the MaskEdit property of an ActiveX control.

Figure 48.1   Mask Edit property page in design mode

The list box allows the user to select from a list of sample masks. The edit controls allow the user to test the mask before applying it to the ActiveX control. You add controls to the property page the same as you would to a form.

Associating property page controls with ActiveX control properties

After you have added all the controls you need to the property page, you must associate each control with its corresponding property. You make this association by adding code to the property page's implementation unit. Specifically, you must add code to the UpdatePropertyPage and UpdateObject methods.

Updating the property page

Add code to the UpdatePropertyPage method to update the property's control on the property page when the properties of the ActiveX control change. You must add code to the UpdatePropertyPage method to update the property page with the current values of the ActiveX control's properties.

For example, the following code updates the property page's edit box control (InputMask) with the current value of the ActiveX control's (OleObject's) EditMask property:

procedure TPropertyPage1.UpdatePropertyPage;
begin
  { Update your controls from OleObjects }
  InputMask.Text := OleObject.EditMask;
end;

Updating the object

Add code to the UpdateObject method to update the property when the user changes the controls on the property page. You must add code to the UpdateObject method in order to set the properties of the ActiveX control to their new values.

For example, the following code sets the EditMask property of an ActiveX control (OleObject) using the value in the property page's edit box control (InputMask):

Note: Include the .TLB file that declares the ICoClassNameDisp interface.

procedure TPropertyPage1.UpdateObject;
begin
  {Update OleObjects from your controls }
  OleObject.EditMask := InputMask.Text;
end;

Connecting a property page to an ActiveX control

To connect a property page to an ActiveX control,

  1. Add DefinePropertyPage with the GUID constant of the property page as the parameter to the DefinePropertyPages method implementation in the controls implementation for the unit. For example,
    procedure TButtonX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
    begin
      DefinePropertyPage(Class_PropertyPage1);
    end;

    The GUID constant, Class_PropertyPage1, of the property page can be found in the property pages unit.

    The GUID is defined in the property page's implementation unit; it is generated automatically by the Property Page wizard.

  2. Add the property page unit to the uses clause of the controls implementation unit.

Exposing properties of an ActiveX control

The properties of an ActiveX control or ActiveForm can appear in a development environment such as Visual Basic, Delphi, or C++Builder. The user of the control or form can then visually manipulate the properties of the control. For properties to appear, they must be defined in the control's type library. For property changes to persist, they must be published. You can add properties to the type library manually, or let Delphi add them automatically. Delphi automatically adds published properties to the type library for you.

Note: Non-published properties that are manually added to the type library will appear in a development environment, but changes made to them will not persist. That is, when the user of the control changes the value of a property, the changes will not be reflected when the control is run.

To expose a property for a control that you created using the ActiveX control wizard, go to the source of the VCL control to expose the necessary properties. If the source is a VCL object and the property is not already published, you must create a descendant of the VCL object and publish the property in the descendant. For example, to publish the Align property of TButton, you can add the following code to the implementation unit of the ActiveX control:

  TAlignButton = class (TButton)
  published
    property Align;
  end;

To expose a property for an ActiveForm,

  1. Select Edit|Add to interface while the implementation unit is open in the editor.
  2. Select Property/Method from the Procedure type drop-down list.
  3. Enter the declaration for the property that will expose the control's property. For example, for the Caption property of a button control you could type,
      property MyButtonCaption: WideString;
    
  4. Choose OK.

    This adds get and set methods to the implementation unit.

  5. Add code to the methods to get and set the controls property. For example, with the button control above, the code would look as follows:
      function TActiveFormX.Get_MyButtonCaption: WideString;
      begin
        Result := Button1.Caption;
      end;
      procedure TActiveFormX.Set_MyButtonCaption(const Value: WideString);
      begin
        Button1.Caption := Value;
      end;
    

Since an ActiveForm is an ActiveX control, there is a type library associated with it, and you can add additional properties and methods to the ActiveForm. For information on how to do this, see "Working with properties, methods, and events in an ActiveX control".

Registering an ActiveX control

After you have created your ActiveX control, you must register it so that other applications can find and use it.

To register an ActiveX control:

Note: Before you remove an ActiveX control from your system, you should unregister it.

To unregister an ActiveX control:

As an alternative, you can use the tregsvr command from the command line or run the regsvr32.exe from the operating system.

Testing an ActiveX control

To test your control, add it to a package and import it as an ActiveX control. This procedure adds the ActiveX control to the Delphi component palette. You can drop the control on a form and test as needed.

Your control should also be tested in all target applications that will use the control.

To debug the ActiveX control, select Run|Parameters and type the client name in the Host Application edit box.

The parameters then apply to the host application. Selecting Run|Run will run the host or client application and allow you to set breakpoints in the control.

Deploying an ActiveX control on the Web

Before the ActiveX controls that you create can be used by Web clients, they must be deployed on your Web server. Every time you make a change to the ActiveX control, you must recompile and redeploy it so that client applications can see the changes.

Before you can deploy your ActiveX control, you must have a Web Server that will respond to client messages. You can purchase a third-party Web Server, such as the Inprise Web Server that ships with the IntraBuilder product, or you can build your own Web Server if you have a version of Delphi that ships with socket components.

The process of deploying an ActiveX control,

  1. Select Project|Web Deployment Options.
  2. On the Project page, set the Target Dir to the location of the ActiveX control DLL as a path on the Web server. This can be a local path name or a UNC path, for example, C:\INETPUB\wwwroot.
  3. Set the Target URL to the location as a Uniform Resource Locators (URL) of the ActiveX control DLL (without the file name) on your Web Server, for example, http://mymachine.inprise.com/. See the documentation for your Web Server for more information on how to do this.
  4. Set the HTML Dir to the location (as a path) where the HTML file that contains a reference to the ActiveX control should be placed, for example, C:\INETPUB\wwwroot. This path can be a standard path name or a UNC path.
  5. Set desired Web deployment options as described in "Setting options".
  6. Choose OK.
  7. Choose Project|Web Deploy.

    This creates a deployment code base that contains the ActiveX control in an ActiveX library (with the OCX extension). Depending on the options you specify, this deployment code base can also contain a cabinet (with the CAB extension) or information (with the INF extension).

    The ActiveX library is placed in the Target Dir of step 2. The HTML file has the same name as the project file but with the HTM extension. It is created in the HTML Dir of step 4. The HTML file contains a URL reference to the ActiveX library at the location specified in step 3.

    Note: If you want to put these files on your Web server, use an external utility such as ftp.

  8. Invoke your ActiveX-enabled Web browser and view the created HTML page.

When this HTML page is viewed in the Web browser, your form or control is displayed and runs as an embedded application within the browser. That is, the library runs in the same process as the browser application.

Setting options

Before deploying an ActiveX control, specify the Web deployment options that should be followed when creating the ActiveX library.

Web deployment options include settings to allow you to set the following:

Compress files by setting CAB file

A cabinet is a single file, usually with a CAB file extension, that stores compressed files in a file library. Cabinet compression can dramatically decrease download time (up to 70%) of a file. During installation, the browser decompresses the files stored in a cabinet and copies them to the user's system. Each file that you deploy can be CAB file compressed.

Sign the files

Code signing allows the user of the control to determine with certainty who wrote the control and that the code has not been modified since it was signed. Each file that you deploy, including packages and additional files, can be code signed.

Code signing generates a digital signature that is added to the file. ActiveX-enabled Web browsers that are set to enforce maximum security will not display ActiveX controls that are not code-signed.

Note: Delphi does not provide the credentials and private key required for code signing. Information on how to obtain these files is available from Microsoft.

Set options for packages

You can set specific options for each required package file as part of your deployment. These packages can each be code signed and put into CAB files. Packages that ship with Delphi are already code signed with the Inprise signature.

If you choose different combinations of package, CAB file compression, and code signing options for your ActiveX library, the resulting ActiveX library may be an OCX file, a CAB file containing an OCX file, or an INF file. See the Option combinations table below for details.

Web Deploy Options Default checkbox

Checking this box saves the current settings from the Project, Packages, Additional Files and Code Signing pages of the Web Deployment Options dialog box as the default options. If it is not checked, the settings affect only the open ActiveX project.

To restore the original settings, delete or rename the DEFPROJ.DOF file.

INF file

If your ActiveX control depends on any packages or other additional files, these must be included when you deploy the ActiveX control. When the ActiveX control is deployed with additional packages or other additional files, a file with the INF extension (for INFormation) is automatically created. This file specifies various files that need to be downloaded and set up for the ActiveX library to run. The syntax of the INF file allows URLs pointing to packages or additional files to download.

Web deployment options are displayed in the following tabs and described in sections below:

Option combinations

The following table summarizes the results of choosing different combinations of package, CAB file compression and code signing Web deployment options.

Packages and/or additional files

CAB file compression

Code signing

Result

No

No

No

An ActiveX library (OCX) file.

No

No

Yes

An ActiveX library file.

No

Yes

No

A CAB file containing an ActiveX library file.

No

Yes

Yes

A CAB file containing an ActiveX library file.

Yes

No

No

An INF file, an ActiveX library file, and any additional files and packages.

Yes

No

Yes

A CAB file containing an INF file, an ActiveX library file, and any additional files and packages.

Yes

Yes

No

An INF file, a CAB file containing an ActiveX library, and a CAB file each for any additional files and packages.

Yes

Yes

Yes

A CAB file containing an INF file, a CAB file containing an ActiveX library, and a CAB file each for any additional files and packages.

Project tab

The project tab enables you to specify file locations, URL, and other deployment options for the project. The options on the project tab apply to the ActiveX library file or CAB file containing the ActiveX control and become the default options for any packages and additional files deployed with the project.

Directories and URLs

Meaning

Target Dir

Location as a path of the ActiveX library file on the Web server. This can be a standard path name or a UNC path.

Example: C:\INETPUB\wwwroot

Target URL

Location as a Uniform Resource Locator (URL) of the path for the ActiveX library file on the Web Server.

Example: http://mymachine.Inprise.com/

HTML Dir

Location as a path of the HTML file that contains a reference to the ActiveX library. This can be a standard path name or a UNC path.

Example: C:\INETPUB\wwwroot

Note: The locations specified are paths only, not complete file names.

In addition to specifying the locations for your ActiveX files, the project tab also allows you to specify whether to use CAB file compression, version numbers, code signing, and so on. The following table lists the options you can select:

General options

Meaning

Use CAB file compression

Compress the ActiveX library, and required packages and additional files, unless specified otherwise. Cabinet compression stores files in a file library, which can decrease a file's download time by up to 70%.

Include file version number

Include version number contained in Project|Options VersionInfo.

Auto increment release number

Automatically increment the projects release number contained in Project|Options VersionInfo.

Code sign project

Code sign the ActiveX library or CAB file containing the ActiveX library, and, unless specified otherwise, any DLLs or additional files to deploy. Code signing identifies the author and company of the control. Its digital signature assures users of the control that the control has not been modified since it was signed.

Deploy required packages

If checked, deploy the project's required packages.

Deploy additional files

If checked, deploy the additional files specified on the Addition Files tab with the project.

Packages tab

The packages tab lets you specify how to deploy the packages used by the project. Each package can have its own settings. When deploying your ActiveX control, you can specify individual deployment options for each required package file used by the project as part of your deployment. Each of these packages can be code signed and put into CAB files. Packages that ship with Delphi are already code signed with the Inprise signature.

Packages used by this project

To modify the settings for a particular package, select the package in the "Packages used by project" list box, and modify the settings as needed.

CAB options

CAB option

Meaning

Compress in a separate CAB

Create a separate CAB file for the package. This is the default.

Compress in a project CAB

Include the package in the project CAB file.

Output options

The output options allow you to specify if the package has version info and if it is code signed.

Output option

Meaning

Use file VersionInfo

Get the version info from the resource in the package file and enter it into the INF file for the project.

Code sign file

Code sign the package or CAB file containing the package.

Directory and URL options

Directory and URL option

Meaning

Target URL (or leave blank to assume file exists on target machines)

Location as a Uniform Resource Locators (URL) of the package on your Web Server. If left blank, the Web browser assumes the file exists on the target machine. If the package is not found on the target machine, the download of the ActiveX control fails.

Target directory (or leave blank to assume file exists on server)

Location as a path of the package on the Web server. This can be a standard path name or a UNC path. Leave blank to assume the file exists and ensure that it will not be overwritten.

Additional Files tab

The Additional Files tab enables you to specify additional files, such as .DLL files, .INI files, resources, etc., that must be deployed with the ActiveX control.

To add a file to be deployed, click on the Add button. This brings up a dialog from which you can browse and select a file. Each file you add is added to the "Files associated with project" list box.

Files associated with project

To modify the settings for a particular file, select the file in the "Files associated with project" list box, and modify the settings as needed.

CAB options

CAB option

Meaning

Compress in a separate CAB

Create a separate CAB file for the file. This is the default.

Compress in a project CAB

Include the file in the project CAB file.

Output options

Output option

Meaning

Use file VersionInfo

If the file contains VersonInfo resources, get the version info from the resource in the file and enter it into the INF file for the project.

Code sign file

Code sign the file or CAB file containing the file.

Directory and URL options

Directory and URL option

Meaning

Target URL (or leave blank to assume file exists on target machines)

Location as a Uniform Resource Locators (URL) of the file on your Web Server. If left blank, the Web browser assumes the file exists on the target machine. If the file is not found on the target machine, the download of the ActiveX library fails.

Target directory (or leave blank to assume file exists on server)

Location as a path of the file on the Web server. This can be a standard path name or a UNC path. Leave blank to assume the file exists and ensure that it will not be overwritten.

Code Signing tab

The Code Signing tab provides a way for users of the control to determine who wrote the control and to be assured that the control has not been modified since it was signed. Each file that you deploy can be code signed. Signing data does not alter it; it generates a digital signature that is added to the file.

To create a digital signature, a hash value (also known as a message digest) is first created using the selected Cryptographic digest algorithm. This hash value is then signed, using the Private key.

For the private key and credentials certificate files, contact Microsoft Corporation.

Required information

To code sign your ActiveX control, you must provide a private key and credentials certificate file. Specify these values in the Required Information section of the Code signing tab.

Required information

Meaning

Credentials file

To obtain this file, contact Microsoft.

Private key

The private key is known only to its owner and is used to generate the signature. To obtain this file, contact Microsoft.

Optional information

In addition to the required information, you can optionally add information to allow clients to obtain the application and company name:

Optional information

Meaning

Name of this application

Application name as you would like it to appear in the digital certificate displayed by the Web browser.

Application or company URL

A URL that provides a link to a Web tab for the product or company.

Timestamp server

Each vendor has a certificate that they use when code signing the file and this certificate must be renewed each year. Vendors often timestamp their digital signatures to verify that their vendor certificate was valid when the file was code signed. You can choose a timestamp server that generates the timestamp for your digital signature.

Timestamp server

Meaning

Default

Use the default timestamping server available on the Internet, Verisign.

None

Do not timestamp this control. Note that code signs without timestamps may become invalid.

Custom

Specify the name of a different timestamp server.

URL

Specify the location of the custom timestamp server on the Internet.

Cryptographic digest algorithm

Choose one of the following cryptographic digest algorithms. MD5 is the most commonly used and the default. You may want to select one algorithm over the other if your browser does not support the other.

Cryptograhic digest algorithm

Meaning

MD5

The MD5 hashing algorithm was developed by RSA Data Security, Inc. This algorithm generates 128-bit hash value.

SHA 1

The SHA hashing algorithm was developed by the National Institute of Standards and Technology (NIST) and by the National Security Agency (NSA). This algorithm generates a 160-bit hash value.