RAD Studio |  |

Creating and Registering the Component (Dialog Box)

Creation of every component begins the same way: create a unit, derive a component class, register it, compile it, and install it on the Tool palette. This process is outlined in Creating a new component.

For this example, follow the general procedure for creating a component, with these specifics:

- Call the component's unit AboutDlg.
- Derive a new component type called TAboutBoxDlg, descended from TComponent.
- Register TAboutBoxDlg on the Samples page of the Tool palette.

The resulting unit should look like this:
Copy Code

    unit AboutDlg;
    interface
    uses
      SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms;
    type
      TAboutBoxDlg = class(TComponent)
      end;
    procedure Register;
    implementation
    procedure Register;
    begin
      RegisterComponents('Samples', [TAboutBoxDlg]);
    end;
    end.

Copy Code

    #include <vcl\vcl.h>
    #pragma hdrstop
    #include "AboutDlg.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init);
    //---------------------------------------------------------------------------
    static inline TAboutBoxDlg *ValidCtrCheck()
    {
      return new TAboutBoxDlg(NULL);
    }
    //---------------------------------------------------------------------------
    namespace AboutDlg {
    {
      void __fastcall PACKAGE Register()
      {
        TComponentClass classes[1] = {__classid(TAboutBoxDlg)};
        RegisterComponents("Samples", classes, 0);
      }
    }

Copy Code

    #ifndef AboutDlgH
    #define AboutDlgH
    //---------------------------------------------------------------------------
    #include <vcl\sysutils.hpp>
    #include <vcl\controls.hpp>
    #include <vcl\classes.hpp>
    #include <vcl\forms.hpp>
    //---------------------------------------------------------------------------
    class PACKAGE TAboutBoxDlg : public TComponent
    {
    private:
    protected:
    public:
    __published:
    };
    //---------------------------------------------------------------------------
    #endif

The new component now has only the capabilities built into TComponent. It is the simplest nonvisual component. In the next section, you will create the interface between the component and the dialog box.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!