Posted by John, DelphiLand Team on September 14, 2007
In Reply to component template in turbo delphi explorer? posted by Fred Green on
September 13, 2007
: I have set up components and a procedures, that I have stored in Component Templates. For example: in Panel2Edits I saved this:
: TForm1 = class(TForm)
: Panel1: TPanel;
: Edit1: TEdit;
: Button1: TButton;
: Edit2: TEdit;
: Label1: TLabel;
: procedure Button1Click(Sender: TObject);
: procedure TForm1.Button1Click(Sender: TObject);
: Label1.Caption := Edit1.Text + '/' + Edit2.Text;
: In my old version of Delphi this is simple. But does Turbo Delphi Explorer also have Component Templates...
Also in Turbo Delphi Explorer you can save Component Templates, like in the previous versions of Delphi. Just a quick overview for readers who never used this feature:
To save a component template:
1. On your form, select all of the desired components: press Ctrl and drag a selection rectangle with the mouse.
Or alternatively, click on the first component, press Shift and one by one click the other desired components.
Or alternatively, like in this example where all the desired components are contained by a panel, click on the panel: this will select the panel plus the components. Tip: putting all of the components on a panel keeps them together, that's easier afterwards when you make use of the component template.
2. In Delphi's menu, select Component / Create Component Template.
3. In the dialog that appears, enter the desired component name. In our example, this would be "Panel2Edits".
4. Enter the name of the name of the page on the component palettewhere you want the template to be shown. This can be any existing page, or a new page name. Example: "Panels2". Next, click the OK button.
Let's test the component template:
1. Start a new project.
2. On the Component Palette, click on Panels2 and next click on Panel2Edits.
3. Click somewhere on your form: a panel with the saved layout and components will be dropped on your form, and the event handler(s) will be added to your code.
4. Next you can drag the panel to the desired location. Here it comes in handy, if at the time of creating the component template, you had put the components on a "container": the panel keeps them nicely together.
You can add as many groups of components as you wish to the same form. Delphi will automatically rename the added components and procedures, thus preventing naming conflicts.
Note: a component template is not a component "class". It's only a scheme that contains the properties for a number of other components. If you look at your source code, you won't see any trace of the template, it looks just as if you added the components yourself.
In other words: a component template does not create a class in your code for a new component with its own properties and methods. It is only a script saying "add the following components to the form and set their properties as follows:..."
With component templates you can build your own library that saves you lots of time later on. They are also great for saving stuff that you used in one project, for later re-use in new projects.