Delphi also provides a Component palette to simplify adding components (reusable code) to forms. Some of the advantages are
To be added to the Component palette, your code needs to be based on TComponent, or one of its descendants. This is the basic hierarchy discussed here.
TObject / TPersistent / TComponent / TControl / TWinControl |
TComponent | These have no visual representation at run time and have no associated events. Your code must draw an icon at design time. (This should have been built-in.) |
TControl | These are displayed at both design time and run time. There are a number of protected events that your control can publish. Your code draws the visual representation. |
TWinControl | These controls are drawn by the Windows operating system. |
In Delphi 5, the Component palette (a toolbar with multiple tabs) is at the top of the screen. Using a Delphi package (dpk file) and the Register procedure, you can add icons that represent your components to one of the existing tabs, or you can create new tabs - your choice.
(This is one of the many reasons that I truly hate the new versions of Delphi - the Component palette toolbar was replaced with a list that is very difficult to use with a mouse. Between this and the totally broken help system, I have no problem reporting that the Delphi user interface (post Delphi 7) is user hostile. Add to that the fact that all strings are now unicode, and there is no reason to ever move from Delphi 5 to a less capable product.)
The information used to produce the Component palette is stored in blp files and the registry.
HKEY_CURRENT_USER\Software\Borland\Delphi\5.0\Known Packages $(DELPHI)\Bin\dclstd50.bpl = Borland Standard Components $(DELPHI)\Projects\Bpl\dcl_mcSci.bpl = MicroCline Science Components |
In every case I've checked, the bpl files in this registry key are also in the library search path. It seems logical that only the registry entry is important - but who knows?
HKEY_CURRENT_USER\Software\Borland\Delphi\5.0\Palette Standard = Frames;TMainMenu;TPopupMenu;TLabel;TEdit;TMemo;TButton; TCheckBox;TRadioButton;TListBox;TComboBox;TScrollBar; TGroupBox;TRadioGroup;TPanel;TActionList; |
Note that each tab is a separate parameter - in this example, the Standard tab - and that the value is just the list of displayed components (in the displayed order). The icons are bitmap resources with the same names stored in the associated bpl files.
C:\Program Files\Borland\Delphi5\Bin\dclstd50.bpl |
When a component is placed on a form
Register the Control
unit mcSci_Register; { This allows the centralization of all the science components 07-28-14 Start of file } interface procedure Register; // must be in the interface section {//R xx.dcr} // a dcr with this unit name will be automatically added to the dpk implementation uses Classes, mcTemperature_frame; procedure Register; begin RegisterComponents('mc', [TmcTemperature_UIFrame]); // may contain multiple components end; end. |
These are the dpk lines that include resources
{$R *.RES} {$R '..\source\mcSci_Register.dcr'} |
Each source file may have its own Register procedure. This is the only procedure name that I know of that can be repeated without causing without causing some kind of conflict.
Use a Package
File / New... / New / Package |
Once it has a proper name, and the other instructions on creating a package are followed, the package is compiled and installed.
Author: Robert Clemenzi