Delphi/CB
•  Greatis •  Security •  AppDatabase •  Utilities •  Visual Basic • .NET •  just4fun
Delphi / C++ Builder
Components, utilities and tips for Delphi and C++ Builder developers
More info
Form Designer FAQ
Form Designer Home
Delphi Components
See also
Products
Object Inspector
Runtime Fusion
Print Suite
Commented Image
Image Editor  new!
Delphi Toys
Ultimate Pack  hot!

FAQs
Object Inspector FAQ
Print Suite FAQ
Image Editor FAQ

Links
Software for .NET
Software for VB 6
Delphi Tips & Tricks

Services
Outsourcing
Using the component palette
Form Designer package contains the special FDCmpPal unit, that contains the ready-to-use function for creation the component palette based on TPageControl.

The CreatePaletteButton function creates the palette button.

function CreatePaletteButton(
  AParent: TWinControl;                       // the parent control
  AClass: TComponentClass;                    // button component class
  ALeft,ATop: Integer;                        // coordinates
  ClickEvent: TNotifyEvent): TPaletteButton;  // the selection event
The last parameter in the function is event (TNotifyEvent) that is called when the user selects the button. TPaletteButton returned by the function is a TSpeedButton descendant with the new ComponentClass property. This property contains the class passed to the CreatePaletteButton function and can be used in the event handler passed as ClickEvent.
type
  TPaletteButton = class(TSpeedButton)
  public
    property ComponentClass: TComponentClass;
  end;
To create the event handler just define the procedure compatible with TNotifyEvent in any object used in your application (easiest way is to do iy in the form) and use the passed Sender as the TPaletteButton object to know the component selected by user.
type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
    procedure ExampleClickEvent(Sender: TObject);
  end;
...
procedure TForm1.ExampleClickEvent(Sender: TObject);
begin
  ShowMessage(
    (Sender as TPaletteButton).ComponentClass.ClassName+
    ' selected');
end;
You can use the ComponentClass property for creating the new component instance
var
  NewComponent: TComponent;
...
  NewComponent:=TComponent(frmToolForm.ComponentClass.Create(Self));
To create the multi-page palette drop TPageControl onto your form and call the CreatePalettePage function for each needed page.
function CreatePalettePage(               // returns TTabSheet object
  APageControl: TPageControl;             // page control for palette
  ACaption: string;                       // palette page caption
  AClasses: array of TComponentClass;     // array of classes
  ClickEvent: TNotifyEvent): TTabSheet;   // the selection event
The following code creates two pages with three components on each page.
  CreatePalettePage(PageControl1,'Standard',
    [TButton,TLabel,TEdit],PaletteButtonClick);
  CreatePalettePage(PageControl1,'Additional',
    [TBitBtn,TSpeedButton,TMaskEdit],PaletteButtonClick);
Each page contains the special edit button with the arrow icon with the ComponentClass = nil.

If you want to select the edit mode (when the edit button is selected) from your code just use the EditMode procedure and pass your TPageControl as parameter.

procedure EditMode(APageControl: TPageControl);
The icon bitmaps for the buttons are loaded from the resources included into executable file. Form Designer has two resource files included the standard components icons: STD.RES (included all non-data-aware components icons) and DB.RES (included icons of data-aware components). The STD.RES file is included into project by default in the FDMain unit, so you don't need to include this file yourself in the FDMain unit is used in your project. If you want to use your own or 3rd party components in the palette, just create the resource file contained bitmap resources (24x24 pixels) for each new component. The bitmap resources must be named as the new components (for instance, the resource for TSpecialButton must be named as "TSpecialButton"). If you have DCR files of your own or third-party components these files can be included too by $R compiler directive.

Greatis Software Greatis | Security | AppDatabase | Utilities | Delphi/CB | Visual Basic | .NET | just4fun

Contacts | Add to Favorites | Recommend to a Friend | Privacy Policy | Copyright © 1998-2008 Greatis Software