Suspending Program Execution

Breakpoints allow you to suspend program execution. Once program execution has been suspended, you can check the values of variables and properties, see environment settings, and examine sections of code line by line without having to step through all your code.

Tip   You can also suspend execution of a program running in the Trace window by pressing ESC.

Suspending Execution at a Line of Code

You can set breakpoints in your code to suspend program execution in several different ways. If you know where you want to suspend program execution, you can set a breakpoint directly on that line of code.

To set a breakpoint on a particular line of code

In the Trace window, locate the line of code you want to set the breakpoint on and do one of the following:

  1. Position the cursor on the line of code.

  2. Press F9 or click the Toggle Breakpoints button in the Debugger toolbar.

    -or-

  • Double-click in the gray area to the left of the line of code.

A solid dot is displayed in the gray area to the left of the line of code to indicate that a breakpoint has been set on that line.

Tip   If you are debugging objects, you can locate particular lines of code in the Trace window by choosing the object from the Object list and the method or event from the Procedure list.

You can also set breakpoints by specifying locations and files in the Breakpoints dialog box.

Examples of Locations and Files for Breakpoints

Location File Where execution suspends
ErrHandler
C:\Myapp\Main.prg The first executable line in a procedure named ErrHandler in Main.prg.
Main,10
C:\Myapp\Main.prg The tenth line in the program named Main.
Click
C:\Myapp\Form.scx The first executable line of any procedure, function, method or event named Click in Form.scx.
cmdNext.Click
C:\Myapp\Form.scx The first executable line associated with the Click event of cmdNext in Form.scx.
cmdNext::Click
  The first executable line in the Click event of any control whose ParentClass is cmdNext in any file.

Suspending Execution When Values Change

If you want to know when the value of a variable or property changes, or when a run-time condition changes, you can set a breakpoint on an expression.

To suspend program execution when the value of an expression changes

  1. From the Tools menu in the Debugger window, choose Breakpoints to open the Breakpoints dialog box.
  2. From the Type list, choose Break when expression has changed.
  3. Enter the expression in the Expression box.

Examples of breakpoint expressions

Expression Use
RECNO( )
Suspend execution when the record pointer moves in the table.
PROGRAM( )
Suspend execution on the first line of any new program, procedure, method, or event.
myform.Text1.Value
Suspend execution any time the value of this property is changed interactively or programmatically.

Suspending Execution Conditionally

Often you'll want to suspend program execution, not at a particular line, but when a certain condition is true.

To suspend program execution when an expression evaluates to true

  1. From the Tools menu in the Debugger window, choose Breakpoints to open the Breakpoints dialog box.
  2. From the Type list, choose Break when expression is true.
  3. Enter the expression in the Expression box.
  4. Choose Add to add the breakpoint to the Breakpoints list.

Examples of breakpoint expressions

Expression Use
EOF( )
Suspend execution when the record pointer has moved past the last record in a table.
'CLICK'$PROGRAM( )
Suspend execution on the first line of code associated with a Click or DblClick event.
nReturnValue = 6
If the return value of a message box is stored to nReturnValue, suspend execution when a user chooses Yes in the message box.

Suspending Execution Conditionally at a Line of Code

You can specify that program execution be suspended at a particular line only when a particular condition is true.

To suspend program execution at a particular line when an expression evaluates to true

  1. From the Tools menu in the Debugger window, choose Breakpoints to open the Breakpoints dialog box.

  2. From the Type list, choose Break at location if expression is true.

  3. Enter the location in the Location box.

  4. Enter the expression in the Expression box.

  5. Choose Add to add the breakpoint to the Breakpoints list.

  6. Choose OK.

    Tip   It is sometimes easier to locate the line of code in the Trace window, set a breakpoint, and then edit that breakpoint in the Breakpoints dialog box. To do this, change the Type from Break at location to Break at location if expression is true and then add the expression.

Removing Breakpoints

You can disable breakpoints without removing them in the Breakpoints dialog box. You can delete "break at location" breakpoints in the Trace window.

To remove a breakpoint from a line of code

In the Trace window, locate the breakpoint and do one of the following:

  • Position the cursor on the line of code, and then choose Toggle Breakpoints from the Debugger toolbar.

    -or-

  • Double-click the gray area to the left of the line of code.

See Also

Isolating Problems | Seeing Stored Values | Testing and Debugging Applications | Output Display | Trace | Debugger