MFSoft Delphi Tutorial, Lesson 1

Welcome to the first lesson of my Delphi tutorial. Before you read on, it is recommended that you have a look at the Overview.

Creating Windows applications using Borland Delphi is very simple. The process can be divided into three steps:
1. Placing components on the form
2. Setting the properties of the components
3. Writing the code

To see these three steps in practice, we will create a simple 'Hello World' application. It will consist of a Form, a Button and a Label. When you press the Button, the Label will show 'Hello World'. Ok, let's get started.

1. Placing components on the form


To place a Button on the form, click once on the Button component on the toolbar. Then move the mouse cursor over to the Form and click on the Form where you want the Button to be. Repeat the same procedure with the Label component.


It will look something like this. Actually you can run your application now. Simply press F9, click Ok to save your project and it's running.


Try to click on the button. Nothing happens? Well, since we have not added any code yet, there are no instructions for what will happen when you press the button. This will be done later. For now, exit your application (click on the ).

2. Setting the properties of the components

To change the text 'Button1' on the button, we change the value of its Caption property. Click on the Button once ('select' the Button), move to the Object Inspector and enter the new value on the Caption row.


To remove the text from the Label, we set the Caption property to '' (empty string). Select the Label and delete the text 'Label1' on the Caption row of the Object Inspector.


If we run our application now, we see that we have made some progress since the first step. Press F9 to run.


The Button and the Label now show the messages we want them to do. However, it still doesn't happen anything if we press the Button. We will deal with this now.

3. Writing the code

To specify what will happen if we press the button, we enter code for the OnClick event of the Button. Select the button, move over to the Object Inspector and click on the Events tab.


Double click on the OnClick row. The Code Editor will popup and a procedure for the OnClick event will be created.


You can fill this empty procedure with code that is going to be executed when you press the Button. The task of this application was to let the Label show the 'Hello World' message when we click on the button, remember?


This code should do the trick. It will be explained in the next lessons. Just type it in, run the application and press the Button.


Here we go! Hello World!

As you have noticed by now, this is not a very useful application. However, by creating it you have learnt the three essential steps of creating any application in Borland Delphi. Creating applications in other 'visual' programming languages like Visual Basic or Borland C++ Builder is done in the same way, it is sort of a standard. But once you have learnt some more Delphi, you will probably not change to another programming language unless you have to. Delphi has all the features you will ever need.




For comments or questions, please contact delphi@mfsoft.com
Copyright © 1998 MFSoft International. All rights reserved.