Basic Delphi - Getting Started

The Delphi IDE

Throughout this tutorial, I'll be using Delphi 7. Versions prior to that are very similar so most of what follows applies equally to earlier versions. The "User Interface" of Delphi 2006 is quite different so, although most of the substance of what follows applies, you will need to adapt it to suit the Delphi 2006 environment.

I'll assume that you've installed Delphi 7 and started the program. The opening display is shown below.

the IDE

The Delphi display can be confusing at first because it comprises a number of separate windows and you can see the Windows desktop, or other running applications, underneath. Initially five windows are open but more will appear as you develop a program. However, it becomes second nature once you get used to it!

The four most important windows are indicated in the picture above. The Main Window, The Object Inspector, The Code Window and the first form of an application - Form 1. We'll look at each of these in turn.

The Main Window contains the usual items of any Windows application - the Title Bar, a Menu Bar and a Toobar but there is an additional feature - the Component Palette. This is used to create the visual aspects of your application.

The Component Palette

Component palette

A Windows application consists of a Form containing various objects such as buttons, text boxes, labels and so on. When creating an application, these objects - known as Components - are added to the Form by selecting the component on the Component palette and dragging it onto the Form.

Double-clicking the component on the Component Palette will automatically place the component at the centre of the Form. It can then be dragged into the correct position and resized. Alternatively, the component can be selected on the Component Palette with a single-click and placed on the Form by clicking and dragging on the Form at the required position.

There are a large number of components available on the palette and they are arranged in groups on different Tabs on the palette. Different versions of Delphi have different components (and different Tabs) so don't worry if you see components in the pictures here that you don't have. We'll only be using the basic components that all versions have.

The Form


Initially, the Form is blank except for the Title Bar and a grid of dots. The dots are to help visually align components as you add them to the Form. I find the initial spacing of the dots to be a little wide. They can be adjusted to be closer together by selecting Tools on the Main Window's Menu Bar. Select Environment Options... then the Designer Tab. The size of the grid is adjusted with the two "SpinEdit" Boxes.

The Object Inspector

Object Inspector In common with most modern 'object-oriented' programming languages, each Form and Component on the Form has a set of properties which determine the component's appearance or behaviour. For example, most objects have properties such as Height and Width, whether it is visible and Enabled and so on.

Again, in common with most modern languages, objects can respond to certain events. For example, a button can respond to someone clicking it or a Text Box can respond to someone typing text into it.

The picture shows the Object Inspector window for Form1. By using the Object Inspector, an object's properties can be viewed and edited. For example, with the Object Inspector showing the properties for Form1, in the box to the right of Caption, where it currently says 'Form1', edit the text to read something else. As you type, you will notice the Title Bar of the actual Form changes at the same time.

Similarly, adjust the height of the Form itself by dragging it with the mouse. As you change the height, you will see the value in the Height property in the Object Inspector changing to match.

This is one of the best things about programming in Delphi - the Delphi Editor is always keeping a watchful eye and does its best to stop you making silly mistakes!

The Code Window

code window

If you click on an edge of the Code Window peeking out from behind Form 1, you will bring it to the front. This is the window where both you and Delphi will write the code which drives your program. There is already the basic framework of code written for you. As you add components to the Form, more framework is written for you - all you have to do is fill out the framework to create a functioning program!