Experimenting with Lazarus
You must have Lazarus installed on your PC to carry out this exercise.
Also, you should have written the "Hello World" program, using Lazarus.
The following steps describe experiments you can do to learn more about Pascal and Lazarus.
- If it is not already running, start Lazarus by double-clicking on its Launch Icon , or by using the Start button.
- If your "Hello World" program is not already loaded in the editor, open it by using the menu option and navigate to the folder you saved it in.
- Use the mouse to select HelloWorld.lpi (note that the extension is .lpi) and click on the button Open.
Click OK to confirm that you want to open the project.
You should see the HelloWorld program in the editor.
Press the Run icon near the top left of the Lazarus menu bar, OR press the F9 key to run the program.
After a small delay, you should see a mainly black window appear and at the top, it should say...
Take a look at the Run icon, and you will see that it is no longer green:
The triangle is now grey . This signifies that the program is running.
Press the little red square (with tooltip Stop) to stop the program running.
This is very useful if a program gets stuck in a loop for some unknown reason.The familiar Execution stopped dialogue appears. Press the OK button to continue.
There are several ways to stop a running program:
Click the green triangle to run the program again and experiment with the various ways of stopping the program.
Press the little red square (with tooltip Stop), as we have just seen.
Click the Lazarus toolbar to ensure it has focus, then press Ctrl+F2.
On the console window, click the X at the top right.
On the console window, right click the icon at the top left, and select menu item Close.
The purpose of the readln;
line at the end of the program is to prevent the black window from disappearing
as soon as the rest of the program has finished. Try commenting out the
statement by typing // at the start of the line, so the line becomes //readln;. Then click on the green Run icon.
Anything on a line after // is treated as a comment to help programmers and is not converted to machine code.The black window will disappear before you can see what has been output to it.
In the editor, remove the //.
Notice that the tab at the top left of the editor now says *HelloWorld. The asterisk signifies that the program code has changed since it was last saved. The Save icon on the toolbar also changes from grey to its active state, again indicating that there are unsaved changes.
Click on the Save icon to save the changes you have just made.
Note that the asterisk has gone, and the save icon is now in its inactive (grey) state.Tip: Computers can crash at any time, so always remember to save your work frequently!
Run the program again.
With the readln; back in action, the console window will not vanish, as before, but will wait for your input. Press the Enter key to allow the program to end.
In the editor, change writeln to WRITELN and run the program again.
Pascal is not case sensitive, so the program still runs as it did before.
In the editor, change WRITELN to write and run the program again.
Notice that the cursor is now positioned at the end of Hello World!. The writeln instruction performed this write instruction then positioned the cursor at the start of the following line.
Amend the program to:
- Output “Hello”
- Position the cursor at the start of a new line
- Save the program as Hello. (Accept the default file extension .lpi).
- Run the program to test it.
Various ways of stopping a program
Use of readln to prevent application window from disappearing
Use of comment characters // to comment out the rest of a line
Presence of asterisk to signify that unsaved changes have been made to the code.