Using the RegisterComponents Procedure

From RAD Studio
Jump to: navigation, search

Go Up to Writing the Register Procedure

Within the Register procedure, call RegisterComponents to register the components specified in the ComponentClasses classes array. RegisterComponents is a procedure that takes two parameters: the Page parameter specifying the name of a Tool Palette category and the ComponentClasses parameter specifying the array of component classes to be registered.

Set the Page parameter to the name of the page (category) on the Tool Palette where the components should appear. If the Page named category already exists, the components are added to that category. If the Page category does not exist, Delphi creates a new Tool Palette category with that name.

Call RegisterComponents from the implementation of the Register procedure in one of the units that defines the custom components. The units that define the components must then be compiled into a package and the package must be installed before the custom components are added to the Tool Palette.

Delphi

procedure Register;
begin
  RegisterComponents('System', [TSystem1, TSystem2]);      {add to system category}
  RegisterComponents('MyCustomPage',[TCustom1, TCustom2]); {new category}
end;

C++

namespace Newcomp
{
void __fastcall PACKAGE Register()
{
TMetaClass* classes[1] = {__classid(TMyComponent)};
RegisterComponents("Miscellaneous", classes, 0);
}
}
namespace Mycomps
{
 void __fastcall PACKAGE Register()
{
  //declares an array that holds two components
TMetaClass classes1[2] = {__classid(TFirst), __classid(TSecond)};
  //adds a new palette page with the two components in the classes1 array
RegisterComponents("Miscellaneous", classes1, 1);
  //declares a second array
TMetaClass classes2[1];
  //assigns a component to be the first element in the array
classes2[0]  = __classid(TThird);
  //adds the component in the classes2 array to the Samples page
RegisterComponents("Samples", classes2, 0);
}
}

Defining the Loading State for Components Registered in a Package

By default, the IDE uses smart (lazy) loading of design-time packages installed in the IDE. In this case, only the design-time packages components which are explicitly used in the opened projects are initially loaded by the IDE. This can lead to error messages while opening a project and to run-time errors during the execution of a created application. In such situations you need to explicitly disable smart loading of a package in which these not loaded components are registered. To explicitly disable smart loading of a design-time package call

ForceDemandLoadState(dlDisable)

during the implementation of the Register procedure of this package.

For example you can write:

Delphi

procedure Register;
begin
  RegisterComponents('MyCustomPage',[TCustom1, TCustom2]); 
     {register custom components}
  ForceDemandLoadState(dlDisable);   
     {enforce always load in the IDE all component registered in this unit}
end;

See Also