Back to DFS's Pascal Page


Debugging Your Program

Programs can have two kinds of errors, those of syntax and those of logic. The compiler catches the syntax errors; you have to discover the logic errors yourself.

A. Load Your Pascal Code

ALT-F3 (Close window): Close all open windows.

F3 (Open File): Load the program code you wish to check.

B. Check the Program for Syntax Errors

CTRL-F9: Run the program to ensure that there are no syntax errors. If it does not behave as you had planned, perform parts C and D.

C. Prepare the Environment

  1. CTRL-F7 (Set a Watch): Put the cursor on a variable identifier. The command will open a window to set a watch on the variable. Tap the ENTER key.
  2. ALT-W then T (Tile the Windows on the Screen): The command will tile the screen producing two non-overlapping windows, one for the source code and one for the Watch.
  3. F6 (Go to Next Window) / SHIFT-F6 (Go to Previous Window): Either command will change the focus back to the Source Window, because there are only two windows open.
  4. Repeat steps 1 and 3 for any other variables you wish to keep track of.

D. Checking Your Logic

There are three basic commands to check portions of your program. They are useful for different purposes. Check the values of your variables in the Watch Window before and after each time you use one of these commands to see if your variables contain appropriate values or not.

F4 (Run to Cursor): This command is used after placing the cursor on a line of code. The program will be run until this statement is about to be executed. This command can be used to jump to the portion of your program where you suspect the logic problem to be. It can also be used to check a portion of your code which is suspect.

F7 (Trace into [procedures]): This command will single-step through your code, one statement at a time, including entering procedures.

F8 (Step over [procedures]): This command will single-step through your code, one statement at a time, but it will treat a procedure as a single statement by executing the procedure without entering it.

E. Checking the Screen Output

ALT-F5 (Toggle Screen): How your output looks is always important. Whenever a write or writeln is executed, you can have a look at the Output Screen using this command. Since it is a toggle, using it again will take you back to the Source Window.


© 1997-99 DFStermole
Created 1997
HTMLified 27 Dec 99