Creating a VCL Forms ActiveX Active Form

From RAD Studio
Jump to: navigation, search

Go Up to How To Build VCL Forms Applications

Like a Delphi control, an ActiveX control generates program code when you place the component on a form or other logical container in the IDE. The main difference between an ActiveX control and a Delphi control is that an ActiveX control is language independent. You can create ActiveX controls for deployment to a variety of programming environments on Windows, not just Delphi or C++Builder, for example.

This procedure uses the ActiveX Active Form wizard to create an ActiveX Active Form containing two components. The wizard uses a VCL Form to create the Active Form. To test the Active Form, you can open it by using a simple HTML file and a Web browser. This procedure consists of the following major steps:

  1. Create an ActiveX Library project and an ActiveX Active Form.
  2. Add a button and event handling code.
  3. Test the active form.

To create an Active X Library project and an ActiveX Active Form

  1. Create a directory on your local drive for the ActiveX project. Give it a name that is easy to find, for example, ActiveX.
  2. Choose:
    This creates a Dynamic Link Library [DLL] project that you can use to host in-process ActiveX Objects.
  3. Choose either:
    The Active Form Wizard displays.
  4. Accept the default settings and click OK. The wizard generates the code needed to implement the ActiveX control and adds the code to the project. An ActiveX Active Form displays.

To add a button and event to the Active Form

  1. From the Standard page of the Tool Palette, add TEdit and TButton components to the form.
  2. Select the button.
  3. On the Events tab in the Object Inspector, double-click the OnClick event. The Code Editor opens with the cursor in place in the event handler block for either:
    • TActiveFormX.Button1Click (Delphi)
    • TActiveFormX::Button1Click() (C++)
  4. Enter the following code at the cursor:
    • Delphi:
  • C++:
  1. Save the project files to your ActiveX directory.

To test the Active Form

After you have created, built, and registered your Active Form, you can host it in a Web browser by using a simple HTML file such as this one:

<h1>Active Form<h1>

In the HTML above, the two items that you must change are the values of the:

  • classid (the GUID of the Active Form's CoClass)
  • codebase (the name of the Active Library that contains the Active Form; can have either a .ocx or .dll extension)
  1. In the <project>_TLB unit, find the classid (the underlying GUID value). Here is the code for the above example:

    // *********************************************************************//
    // GUIDS declared in the TypeLibrary. Following prefixes are used:        
    //   Type Libraries     : LIBID_xxxx                                      
    //   CoClasses          : CLASS_xxxx                                      
    //   DISPInterfaces     : DIID_xxxx                                       
    //   Non-DISP interfaces: IID_xxxx                                        
    // *********************************************************************//
      CLASS_TestActiveForm: TGUID = '{3E46CAEF-520F-4B9F-B152-00FF2E006F88}';

    So the classid in this example is 3E46CAEF-520F-4B9F-B152-00FF2E006F88.

  2. Find the correct codebase value by looking at the Factory's registration code. The codebase is the fourth parameter when the factory is constructed, and has the "Class_" prefix:


    So the codebase here is TestActiveForm.

  3. Edit the HTML file and insert your specific values for codebase and classid. Save the file.

  4. Using a Web browser such as Internet Explorer, open the HTML file.

    The Active Form displays in the browser window.

  5. Click the button. A pop-up dialog displays the text in the Edit box.

  6. Change the text, and click the button again. The new text you entered displays in the pop-up.

See Also