Friday 9 April 2010

Delphi Tutorial # 2

Visual Programming Concept

In this tutorial, we’re going to learn about basic visual programming concept. We’re going to learn how to create a form including several components.

There are three steps of visual programming : Creating a user interface, Writing codes and Compiling code and form into an executable file (.EXE). When you run the program, Delphi will compile your codes into an EXE file automatically.

Creating a simple project

To create a project, first you must create a user interface. Resize the blank form into a desired size you like (you have to find out how to resize the form yourself). Set form properties like table shown below :

CaptionMy First Delphi Project
NameMyForm
PositionpoDesktopCenter

Add a label component, it is in Standard page of component palette. Set label properties like table shown below :

CaptionThis is my first Delphi project

Add a button component, it is also in Standard page of component palette. Set button properties like table shown below :

Caption&Exit
NameExitButton

Now, we have a user interface below :

Adding codes for ExitButton

If you want to add some codes to ExitButton, you have to determine the event when the codes will be executed. Then you can write some codes for the event. In this case you have to write some codes for OnClick event of the ExitButton. From the event tab of object inspector, select or double click the OnClick event (see the picture).

Start writing the codes :

procedure TMyForm.ExitButtonClick(Sender: TObject)

begin

 Application.Terminate;

end;

You only have to type a simple code : Application.Terminate; You have to put the(;) after the statement. This code will end your application.

Go to Previous Tutorial or Next Tutorial

0 comments:

Post a Comment

These links are part of a pay per click advertising program called Infolinks. Infolinks is an In Text advertising service; they take my text and create links within it. If you hover your mouse over these double underlined links, you will see a small dialog box containing an advertisement related to the text. You can choose to move the mouse away and go on with your browsing, or to click on the box and visit the relevant ad. Click here to learn more about Infolinks Double Underline Link Ads.