How To Program with Delphi

This article will explain to you how to get started with Delphi programming in a step-by-step tutorial. In this article, we will build a simple 'Hello world' application which changes a text label when button is clicked. You will learn basic steps to design application user interface and how to define event handler that will trigger actions.

Step 1

If you don't have Delphi compiler yet, you can download Turbo Delphi Explorer, a free edition of Delphi for student and hobbyist, from http://www.turboexplorer.com.

Run Delphi application. Click File -> New -> VCL Form Application. Click OK. Delphi will prepare your new project called Project1. Click File -> Save Project As to save this project as HelloWorld. Now, you are ready to code.

Step 2

When you create a VCL form application project, Delphi will create one empty form named Form1. This is your main application window. From the Object Inspector tool, you can find it on the bottom side of Delphi Integrated Development Environment (IDE).  Click and select Caption properties of Form1 and change it to any text you want, for example, Hello Delphi programming.

Find Tool Palette on bottom right of Delphi IDE. Select TButton control and drag-drop it to Form1. Your form will be populated with a button. Select button control and drag it to arrange its position on the form. On Object Inspector, change Caption property to any text, for example Click Me.

From Tool Palette, drag TLabel and drop it on the form. From Object Inspector, change its Caption property to any text, for example Hello world. As you type, you can see that Label control will change its text.

Step 3

Select button control and from Object Inspector, activate Events tab. It is located after Properties tab.

Now look for OnClick event. Double click on it or you can double click on button control on the form. Delphi will generate code block for you which you can fill with your own code. Type your first code between Begin and End block and make it look exactly like the following code.

procedure TForm1.Button1Click(Sender:TObject);

begin

    Label1.Caption:='Hello Delphi Programming';

end;

 

Save your project. Wait until the saving process is complete.

Step 4

Go to Project -> Build HelloWorld. Wait until the building process is complete. If you type it correctly, Delphi should generate no error messages. If you get any error messages, check for syntax error. Delphi displays line information where the error occurred, so it should be easy to spot it if you got any errors.

If you built with success, go to Run -> Run, or you can press F9. You project should come to life. Click button and the text should change to Hello Delphi Programming.

 

Share this article!

Follow us!

Find more helpful articles: