Experimenting with Delphi
You must have Delphi installed on your PC to carry out this exercise.
Also, you should have written the "Hello World" program.
The following steps describe experiments you can do to learn more about Pascal and Delphi.
- If it is not already running, start Delphi by double-clicking on its Launch Icon.
- 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.dpr or HelloWorld.dproj 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 green Run icon near the top left of the Delphi 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...
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.
Click the Delphi 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 //.
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 .dpr or .dproj).
- 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