RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
Classes.RegisterComponents Function

Registers a set of components so that they all appear on the same page of the component palette.

Pascal
procedure RegisterComponents(const Page: string; ComponentClasses: array of TComponentClass);
C++
RegisterComponents(const AnsiString Page, array of TComponentClass ComponentClasses);

Classes

Call RegisterComponents to install a set of components in the IDE. Once a component is registered, it appears on the component palette, where it can be selected and placed on forms or data modules. Registered components can communicate with the Object Inspector to allow the user to get and set properties and events. 

Set the Page parameter to the name of the page on the component palette where the components should appear. If the named page already exists, the components are added to that page. If the named page does not exist, a new palette page with that name is created. 

Pass the components to be registered in the ComponentClasses parameter.

Note: In C++, the ComponentClasses_Size parameter indicates the index of the last class in the ComponentClasses array (one less than the number of classes).
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 appear in the component palette.
Note: After components are registered, users can move them to different palette pages. Once this happens, the component always appears on the new page. Calling RegisterComponents a second time does not influence the page on which the component appears.
 

Delphi Examples: 

 

{
The following code registers several components, some on the
MySystem palette page that already exists, and some on a new
palette page that is created when when the components are
installed.
} 
type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TDemoLabel = class(TGraphicControl)
  private
    FFocusControl: TWinControl;
    procedure SetFocusControl(Value: TWinControl);
    procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
    procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
  protected
    procedure Notification(AComponent: TComponent;
      Operation: TOperation); override;
    procedure Paint; override;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Caption;
    property Color;
    property FocusControl: TWinControl read FFocusControl write SetFocusControl;
    property Font;
    property ParentColor;
    property ParentFont;
  end;

procedure Register;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TDemoLabel }

constructor TDemoLabel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FComponentStyle := FComponentStyle - [csInheritable];
end;

procedure TDemoLabel.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if (Operation = opRemove) and (AComponent = FFocusControl) then
    FFocusControl := nil;
end;

procedure TDemoLabel.SetFocusControl(Value: TWinControl);
begin
  FFocusControl := Value;

  { Calling FreeNotification ensures that this component will receive an
    opRemove when Value is either removed from its owner or when it is
    destroyed. }

  Value.FreeNotification(Self);
end;

procedure TDemoLabel.Paint;
var
  Rect: TRect;
begiN
  Rect := ClientRect;
  Canvas.Font := Font;
  Canvas.Brush.Color := Color;
  Canvas.FillRect(Rect);
  DrawText(Canvas.Handle, PChar(Caption), Length(Caption), Rect,
    DT_EXPANDTABS or DT_WORDBREAK or DT_LEFT);
end;

procedure TDemoLabel.CMDialogChar(var Message: TCMDialogChar);
begin
  if (FFocusControl <> nil) and Enabled and
    IsAccel(Message.CharCode, Caption) then
    with FFocusControl do
      if CanFocus then
      begin
        SetFocus;
        Message.Result := 1;
      end;
end;

procedure TDemoLabel.CMTextChanged(var Message: TMessage);
begin
  inherited;
  Invalidate;
end;

procedure Register;
begin
  Classes.RegisterComponents('MySystem', [TDemoLabel]);
  Classes.RegisterComponents('Samples', [TDemoLabel]);
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!