1. Home
  2. Computing & Technology
  3. Delphi Programming

GETTING STARTED
Delphi For Beginners:
My First Delphi Program.

This article will give you an overview of the ideas behind programming with Delphi. We know what is Delphi, don't we?

   Steps
The first step in developing a Delphi application is to plan what the user will see. We have to design the screens. What menus do you want? How many windows should there be? Will the application have places to enter text (edit boxes)?

In Delphi, the objects a programmer places on the windows (forms) are called components. Some of the components are buttons, edit boxes, labels, combo boxes, option buttons, etc. As you will see, all these components (objects) are standard Windows objects. Depending on which version of Delphi you have, you start with more than 100 components at your disposal, and than you can add components by buying them or creating them.

Only after you design the interface of your application, you should start writing code.

Further steps in developing a Delphi application:

  1. Customize the windows that user sees. This means placing components on the form – you literally draw the user interface, almost as though you are using a paint program
  2. Decide what events the components on the form should recognize. For example: we have to specify what will happen if user clicks the button. An event is something that occurs as a result of a component's interaction with the user or with Windows.
  3. Write the event procedures for those events. The programming code in Delphi that tells your program how to respond to events like mouse clicks is inside what Delphi calls event procedures.

   Let's start
We'll begin by launching Delphi. When you first start the program, you are presented with both a blank form and the IDE (integrated development environment).

Object Inspector My first Delphi program

At the top of the blank form is the title bar with its caption. To the left of the form, the Object Inspector shows the properties for the form. Choose the caption property and change it from 'form1' to 'My first Delphi program'.

Now press F9 or choose Run-Run from the main menu. Before you even know what has happened, Delphi has built the program. The form is displayed, and the caption shows My first Delphi program. Notice that what you see is an ordinary looking Windows window. This IS a true Windows program. Window can be moved by dragging the title bar, it can be sized, it can be minimized, it can be maximized, and it can be closed by clicking the Close button.

Try it, and finally close it.

You can even locate the program in Windows Explorer (it will probably be in your \Delphi??\ directory as Project1.exe) and double-click on it to run it.

   Give me more!
Ok, ok I know this is not something. So, let us write some code. If you still have your first program running, close it by using ALT-F4.
Click on the Events tab in the Object Inspector window. Double click in the right column of the item marked "OnClick". This brings the Code Editor window to the top of the screen. Delphi generates an event handler for the button's OnClick event. The generated code looks like this:

procedure TForm1.FormClick(Sender: TObject);
begin
| 
end;

Right now, you don't need to be concerned with everything you see here. You only need to understand that the OnClick event handler is a section of code that will be executed every time the form is clicked.
Enter this code at the cursor:

  form1.Caption:='User clicked on the form!';

This code simply assigns the value User clicked on the form to the Caption property of the form.

Now run the program (let's us term project, rather than program, to refer to the combination of programming code and user interface). Click on the form and notice that the caption changes from My first Delphi program to User clicked on the form!.

As you have noticed by now, this is not a very useful application. However, by creating it you have learnt some essential steps of creating any application in Delphi.

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.