Begin Programming Logo
Home | KPL | Object Pascal | General Programming | Code Database | About Us
   
Hello World
   
   

It's now time to write your first program in Lazarus, and there is no better place to start than the classic "Hello World" program.

But firstly, you need to be introduced to something called console mode. Despite the technical sounding name, console mode is actually very simple. It is just where a program runs in a command prompt, which is a DOS-like window which only has simple textual inputs and outputs. The user types the input via the keyboard and the program outputs information via text on the screen. The following is an example of an application running in console mode.

Example Console Program

You are now ready to write your first program in console mode.
Open up Lazarus and click "File - New ...". Then choose "Project - Program".
A new file will appear in the source editor, as shown below.

New Console Program in Lazarus

This appears to be very complicated, but in actual fact you can ignore everything above the "Begin End Block", which is the part at the bottom which says:

begin
end.

This is where your code will go. The rest is just setting up the console application. Now for the code of your Hello World program:

  Writeln('Hello World');
  Readln;

That is all, all you have to do is put that in the Begin End block (with Begin before it and End after it). Now you can run your program by clicking the green arrow in the tool bar or by pressing the F9 key. You should see the following.

Hello World Code and Console Program

If you do, then congratulations, you have finished your Hello World program!
If you don't, then make sure you have done everything correctly and check your code against the screenshot above.

But how does it work? The "Readln" function is meant to get an input from the user, but in this case it just stops the window from closing (try it without and you'll see what I mean). The "Writeln" function is what outputs the "Hello World" string. If you want, you can change the string (text) to anything you want, and then run your program again.

   

Valid XHTML 1.0 Transitional Valid CSS!