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:
-
Start Lazarus by double-clicking on its Launch icon
, or by using the Start button.
After Lazarus has started, you will see the following menu bar:
-
On the menu bar click on Project.
'Project' is circled in purple in the graphic above.
A drop-down menu will appear:
-
On the drop-down menu, click on New Project ....
The Create a new project dialogue appears:
-
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:
-
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
-
Save the file in a suitable folder as 'HelloWorld' by selecting menu item
The name on the first line of the program should change to HelloWorld.
-
Click to the right of 'begin' to place the cursor (a vertical bar) after 'begin'.
-
Press the Return key once (to go onto a new empty line), and carefully type "writeln('Hello World!');"
-
Press the Return key again, and carefully type "readln;"
The program should now look like this:
-
Carefully check that every character is correct. Especially check that the single quotes and the semi-colons are there.
-
The time has come to compile and run the program! Press the green triangle
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:
-
If it did not work, you will need to check again for errors, and correct them before clicking on the run icon again.
-
Carefully check that every character is correct.
-
Especially check that the single quotes and the semicolons are there.
-
If it did work, there are a few things for you to notice:
The green start icon has now changed to grey
, 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).
-
Press the Return key again, to make the program terminate.
The Execution stopped dialogue appears:
-
Press the OK button.
The dialogue disappears and Lazarus is ready for further instructions from you.
-
Delete the lines between the first line and begin.
The program should now look like this:
-
Confirm that the program runs as before.
For simple programs running in Windows this is all that you really need.
-
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.
If you want to, you can quit from Lazarus by selecting menu item
Alternatively, you can move on to the next topic in this guide.