Setting Breakpoints

To set breakpoints we use the same version of program InsertionSort as in the previous section (Displaying Values).

To set a breakpoint in Lazarus or Delphi, click in the gutter to the left of the code line. In Delphi you can select menu item Run > Add Breakpoint > Source Breakpoint. We can set a breakpoint at the start of the while loop. Now when we run the program as usual (for example by pressing F9), the program pauses at the start of the while loop. We positioned the cursor over the red circle and obtained the following screenshot.

Breakpoint

Breakpoint

Four presses of F7 take us back to the start of the loop. This is the position where we examined the values of variables in the previous section. We can do better than this by setting the Pass Count property of the breakpoint to 2:

Setting breakpoint properties

Setting breakpoint properties

Now a single click of F9 takes us to our desired state of the program. Alternatively, we could set the condition property to Current=0. To view the Breakpoint Properties window, (i) position the cursor on the red circle marking the breakpoint in the editor, (ii) right click and (iii) select Breakpoint properties... (Delphi) or View Breakpoint Properties (Lazarus) from the pop-up menu. Alternatively in Delphi, (i) press CTRL+ALT+B to see a list of breakpoints, (ii) select the required breakpoint and (iii) press CTRL+E.

Programming - a skill for life!

Stepping through code, setting breakpoints, error handling and range checking