1. Technology

Your suggestion is on its way!

An email with a link to:

http://delphi.about.com/od/beginners/l/aa050702b.htm

was emailed to:

Thanks for sharing About.com with others!

Creating your first 'Hello World' Delphi Application
Page 2: Writing code, compiling and running your application for the first time.
 More of this Feature
• Page 1: Creating a project
• Page 3: Saving your work, geting help
 Join the Discussion
"Post your views and comments to this chapter of the free Delphi Programming Course"
Discuss!
 Related Resources
• A Beginner's Guide to Delphi Programming.TOC

   Hello Delphi
Now that we've created a project, we can begin work on our first application. This first application will be pretty simple - we'll change the caption of the (main) form once the application is executed. The change will be initiated from code - no user interaction will be necessary.

To add the code that changes the caption of the form we need to *call* the Code Editor window. If you have the Project Manager displayed on the screen, double click the Form1. This will bring up the Form designer window to the front. Another way to bring the Form1 to the front of the screen is to select Form1 from the Window menu. Once Form1 is on top and active, double click it. This action has the following result: the Code editor is positioned on the top of the screen and Delphi creates the skeleton code for the new event handler.
Note: another way of achieving the same result is to activate Form1 in the Object Inspector, select the Events tab and double click in the OnCreate column value.

As stated in the second chapter of this course, each form has a collection of events – such as a mouse click, keypress, or component activation – for which you can specify some additional behavior. In this case the event is called OnCreate. This event occurs when the form is created.
The skeleton code looks like:

procedure TForm1.FormCreate(Sender: TObject);
begin
//this is where your code goes
end

For the moment do not get bothered with the meaning of the text you see.

Now alter the code so that it looks like:

procedure TForm1.FormCreate(Sender: TObject);
begin
  Caption := 'Hello Delphi! ' + DateTimeToStr(Now);
end

Running a project for the first time
To see the results of this action, you need to (successfully) compile and run you project. From the Run menu choose Run or press F9. The compiler will try to build the project and execute your application. If the compiler encounters an error, it displays an Error dialog box. When you choose OK to dismiss the dialog box, the Code editor places the cursor on the line of code containing the error.

Show compile progress

Note: if you want to see progress reports while your program compiles, you'll need to check the "Show compiler progress" check box in the "Compiling and running" section on the Preferences page of the Environment Options dialog box. Call this dialog box by selecting Environment Options from the Tools menu.

Hello Delphi

If everything goes well (it should) your application is executed and you see a blank form on the screen. Note several things. First, the form is blank - there are no dots that make up the grid you see when designing the form look. Second, there is a new button on the Windows Task Bar - when you point to it you'll see that it has the Project1 caption. Third, the caption of Delphi IDE is changed from "Delphi 6 - Project 1" to "Delphi 6 - Project 1 [Running]". And fourth, most important for us, the caption of the form is Hello Delphi ! + *date and time of the execution*.

There is not much you can do with this window, you can move it resize it and finally close it. Every time you (compile and) run this project a form caption will say Hello Delphi with the date and time of the execution.

Ok, I know this is not a lot, but be patient - this is your first project - it is not supposed to do something meaningful. If you want a little more, here goes another simpe example.

Next page > Saving your work, geting help > Page 1, 2, 3

A Beginner's Guide to Delphi Programming: Next Chapter >>
>> Chapter 4: Learn about: properties, events and Delphi Pascal

©2014 About.com. All rights reserved.