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.

  1. If it is not already running, start Delphi by double-clicking on its Launch Icon.
  2. If your "Hello World" program is not already loaded in the editor, open it by using the menu option File > Open ... and navigate to the folder you saved it in.
  3. Use the mouse to select HelloWorld.dpr or HelloWorld.dproj and click on the button Open.
  4. Click OK to confirm that you want to open the project.

    You should see the HelloWorld program in the editor.

  5. 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...


    Hello World!

  6. There are several ways to stop a running 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.

    Click the green triangle to run the program again and experiment with the various ways of stopping the program.
  7. 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 readln; 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.
  8. In the editor, remove the //.
  9. 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.
  10. 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.
  11. Amend the program to:
    1. Output “Hello”
    2. Position the cursor at the start of a new line
  12. Save the program as Hello. (Accept the default file extension .dpr or .dproj).
  13. Run the program to test it.
Features introduced:
  • 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

Programming - a skill for life!

How to write and run Pascal programs in Delphi