Writing your First Pascal Program using Lazarus

Before doing this exercise you must first have Lazarus installed on your PC.

Now we will use the newly installed Lazarus to create a simple program and run it.

The programming culture demands that the first program written in any language should output "Hello World!" to the screen. The steps to do this are as follows:

  1. Start Lazarus by double-clicking on its Launch icon You should be able to find a launch icon like this on your desktop, or by using the Start button.

    After Lazarus has started, you will see the following menu bar:

    The Lazarus Menu Bar, with 'Project' circled in purple to help you find it.

  2. On the menu bar click on Project.
    'Project' is circled in purple in the graphic above.

    A drop-down menu will appear:

    The Project menu

  3. On the drop-down menu, click on New Project ....

    The Create a new project dialogue appears:

    The Lazarus 'Create a new project' dialogue, with 'Program' selected

  4. Click on Program in the list of options, as shown above, and then click on the OK button. If you are using a very recent version of Lazarus you should click on Simple Program instead and you will not see the unnecessary code before begin (making Step 16 redundant).

    You may see the following Project changed dialogue:

    Lazarus 'Project changed' dialogue, which may or may not appear, depending on circumstances

  5. If do see the above Project changed dialogue, just click on the No button.
    (It was a brand new project and so nothing valuable will be lost).
    If you do not see the above dialogue you do not need to do anything in this step.

    You should now be able to see a new project in the Source Editor

    A new project in the Source Editor, with nothing between the begin and end

  6. Save the file in a suitable folder as 'HelloWorld' by selecting menu item Project > Save Project As...

    The name on the first line of the program should change to HelloWorld.

  7. Click to the right of 'begin' to place the cursor (a vertical bar) after 'begin'.
  8. Press the Return key once (to go onto a new empty line), and carefully type "writeln('Hello World!');"
  9. Press the Return key again, and carefully type "readln;"

    The program should now look like this:

    Complete Hello World! program

  10. Carefully check that every character is correct. Especially check that the single quotes and the semi-colons are there.
  11. The time has come to compile and run the program! Press the green triangle Active Green Run icon near the top left of the Lazarus menu bar, OR press the F9 key.
    In case you were wondering, the file will be saved automatically, so you do not need to save it first.

    After a small delay, you should see a mainly black window appear:

    Lazarus Run-time window, with Hello World!

  12. If it did not work, you will need to check again for errors, and correct them before clicking on the run icon again.
    1. Carefully check that every character is correct.
    2. Especially check that the single quotes and the semicolons are there.
  13. If it did work, there are a few things for you to notice:

    The green start icon has now changed to grey Greyed-out Run icon, indicating that the program is still running, and that consequently the icon is inactive.

    There is a blinking white cursor (a horizontal bar) on the black window, indicating that the program is awaiting input (due to the readln; statement).

  14. Press the Return key again, to make the program terminate.

    The Execution stopped dialogue appears:

    'Execution stopped' dialogue.

  15. Press the OK button.
    The dialogue disappears and Lazarus is ready for further instructions from you.
  16. Delete the lines between the first line and begin.

    The program should now look like this:

    Simplified Hello World! program

  17. Confirm that the program runs as before.

    For simple programs running in Windows this is all that you really need.

  18. If you can think of anything we could have made more straightforward for you, then please let us know. If it did not work, then please tell us what went wrong.
Features introduced:
  • New console program opened

  • Program named

  • Text denoted by single quotes

  • Text output to screen

If you want to, you can quit from Lazarus by selecting menu item File > Quit

Alternatively, you can move on to the next topic in this guide.

Programming - a skill for life!

How to install and set up Lazarus to create, edit and run Pascal programs