Basic Delphi - Component Properties

Properties

As I mentioned on the previous page, all components have a lot of Properties in common. Let's have a look at a few of those properties here.

Name

Every component has a Name property. When you add a component to the Form, Delphi will give it a default name. For example, the first button you add will be assigned the name "Button1", the first Label will be "Label1" and so on.

Components are referred by their Name in the code in order to change their other properties so it is usually useful to change the default Name into something more meaningful. There are some rules governing Names: They can be up to 64 characters long, they can consist of letters, numbers and the underscore character but they cannot start with a number.

Upper and lower case letters may be used to improve legibility but both cases are treated as the same. For example DeleteButton and deletebutton both refer to the same component but the first is probably easier to read.

Component names cannot be reserved words. These are generally words which form part of the Delphi language or which have special meanings in the Delphi editing environment.

Caption

Most components have a Caption property. This is simply text which appears on the component and the rules governing the Name do not apply to the Caption as this is purely 'cosmetic' text.

Components such as Buttons, generally have the first letter of their Captions underlined to denote that the character is an accelerator key - that is pressing the alt key and the accelerator key at the same time is the same as 'clicking' the component. Including the & symbol in front of a character in a Caption, underlines the character and automatically makes it an accelerator key.

Size & Position

The size and position of a component are determined by four properties. Width and Height for the size and Left and Top for the position.

The position is usually relative to the top-left corner of the Form unless the component is placed inside another component, for example a GroupBox, in which case, the position is relative to the top-left of that component.


Components

Component palette

The Pointer isn't actually a component. It's purpose it simply to ensure that the mouse pointer is in the correct 'mode' - ensure the pointer button is shown depressed (as in the picture above) before selecting one of the components. If you select a component and then change your mind before putting it on the Form, you can 'reset' the palette by clicking the Pointer button.

To delete a component once you've placed it on the Form, make sure the component is the active component of the Form, by clicking on it (it will show the re-sizing dots), then either right-click on it and select Edit from the popup menu or hit the Delete key.

In Delphi, Forms and components are called Objects. Each object is a self-contained entity and contains code (procedures and functions) to perform its tasks. Information is passed to and from the rest of the program in the form of messages.


Ok, that's enough to get us started. Let's have a go at building a simple text editor to see how we use these components in a real application.

Previous | Next