Use a breakpoint (using breakpoints)
When a user runs a program from Delphi IDE, the program runs at full speed and stops at the place where the breakpoint is set.
New Term
A breakpoint is a flag used to notify the compiler to pause program execution when the program runs to the position where the breakpoint is located.
Setting and clearing breakpoints)
You can click the code editor groove to set the breakpoint. to pause the program execution in a line of code, click the cursor at the position corresponding to the line in the groove, this row is set to a breakpoint. a breakpoint icon (a red circle) appears in the groove, and the line where the breakpoint is located is highlighted in red, for example:
Click the breakpoint icon in the groove to delete the corresponding breakpoint. You can also press F5 or select toggle breakpoint from the shortcut menu of code editor to trigger or cancel a breakpoint.
Note
You can only set breakpoints on lines that can generate actual code. The breakpoint is invalid when a breakpoint is set on a blank line, comment, or declaration line. When a user sets a breakpoint on this type of line, the debugger will give a warning. When you try to set a breakpoint on the next line, an invalid breakpoint warning will be generated:
You can set breakpoints on the end statement line of a function or process.
If a breakpoint is set on an invalid row, code editor displays the breakpoint in green, as shown in.
The program running in the debugger is identical to the normal program running without a breakpoint. When a breakpoint is encountered, the IDE will be mentioned at the top level, the line where the breakpoint is located in the source code is highlighted. If the default color format is used, the line at the stop of the program is highlighted in red. For example, there is a green arrow next to the red breakpoint:
New Term
Execution point refers to the code line to be executed next in the source code.
When you debug the program step by step, the execution point is highlighted in blue and a green arrow symbol is displayed in the code editor groove. Reminder: The line highlighted in blue has not been executed; it is executed only when the recovery program is executed. For example:
Note
When the row where the execution point is located is highlighted in blue, unless the row contains a breakpoint (this row is highlighted in red ). The green arrow in the groove is the most precise indicator of the current execution point because it is not affected by the highlighted display color.
When a program is paused at a breakpoint, you can view the variable, call stack, browse symbol, or step in the code. After checking the variables and objects, you can click the run button to resume program execution. Then the application runs normally again until the next breakpoint is reached.
Note
After a program is paused at a breakpoint, you usually need to check for code writing errors. If you modify the source code in the middle of the debugging session, and then press the run button to restore the program execution, the IDE will display a message box prompting you whether to re-build the source code. If you select Yes, the current process is terminated, the source code is re-compiled, and the program is restarted.
In this way, there is a problem, the program cannot be closed normally, and the resources currently in use are not released. This may cause memory leakage (memory leaks ). We recommend that you terminate the program and re-compile the application.
The breakpoint List window)
Delphi ide records user-set breakpoints. You can view these breakpoints in the breakpoint List window. Select View | debug windows | breakpoint from the main menu to view the breakpoint list, for example:
Note
The pass column does not display the number of times a breakpoint is hit. It only displays the conditions that the user sets for the breakpoint.
1. breakpoint list context menus)
- Enabled-- Allows or disables the use of a breakpoint. If a breakpoint is disabled, its symbols in the breakpoint List window will become grayed out; its breakpoint symbols in the source window will also become grayed out; and the line where the breakpoint is located will be highlighted in green, indicates that the breakpoint is disabled. For example:
- Delete-- Delete a breakpoint.
- View Source-- Scroll the source file in code editor to display the source code lines containing breakpoints.
- Edit Source-- Place the editing cursor on the line containing the breakpoint in the source code. Switch the input focus to the code editor.
- Properties-- The "source breakpoint properties" breakpoint properties dialog box is displayed.
- Breakpoints-- Display sub-menus related to breakpoints, such:
- Dockable-- Determine whether the "breakpoint list" window is available.
Note
The "add" menu item in the shortcut menu does not play much role, because it is much easier to set breakpoints in code editor than to add breakpoints through the "add" command in the breakpoint List window.
2. Enabling and disabling breakpoints)
You can disable or enable breakpoints at any time. If you want to run the program properly, you can temporarily disable the breakpoint in the program. You can enable the breakpoint as needed without re-creating it. The debugger ignores disabled breakpoints.
Enable or disable a breakpoint. In the breakpoint List window, right-click the breakpoint and select Enabled from the shortcut menu.
3. Modifying breakpoints)
To modify a breakpoint, select the properties menu item from the breakpoint List window. The "Source breakpoint properties" dialog box is displayed, for example:
The main reason for modifying a breakpoint is to add a breakpoint condition, which will be highlighted later.
To delete a breakpoint, select the breakpoint in "breakpoint list" and press the "delete" keyboard on the disk. To delete all breakpoints, right-click them and select Delete All ].
The following describes two types of breakpoints: simple breakpoint and conditional breakpoint.
Simple breakpoints)
A simple breakpoint refers to a breakpoint where the program will be suspended as soon as it is executed. The breakpoint set by default is a simple breakpoint. Simple breakpoints do not need to be explained. When a simple breakpoint is reached, the program execution is paused, and the debugger waits for user input. In most cases, simple breakpoints are used. When you need to control the debugging process more, conditional breakpoints are used.
Conditional breakpoint)
If a breakpoint is a conditional breakpoint, the program will be paused only when the predefined conditions are met.
To create a conditional breakpoint, set the breakpoint in code editor. Then, select View | debug windows | breakpoint from the main menu to bring up the "breakpoint list" window, right-click the breakpoint to be set and select properties. The "Source breakpoint properties" dialog box is displayed. In this dialog box, set the breakpoint conditions.
There are two types of conditional breakpoints:
- The first type isConditional expression breakpoint.
In the "condition" field in the "source breakpoint properties" dialog box, enter a conditional expression. For example:
When the program runs, the value of the conditional expression is obtained first when a breakpoint of the conditional expression is met. If the value of the conditional expression is true, the program is paused. If the value of the conditional expression is false, the breakpoint is ignored.
For example, the set conditional expression is x> 20. When the program runs to this breakpoint, if X is greater than 20, the program is paused. If X is not greater than 20, the program continues to run.
- The second type isPass count breakpoint.
For a breakpoint through counting, the program will suspend execution at the breakpoint as long as the number of times the breakpoint hits a specified number. To specify a breakpoint by counting, edit the breakpoint in the "source breakpoint properties" dialog box and specify a value for the pass count field. If you set the count of a breakpoint to 3, the program will suspend the execution of the breakpoint for the third time.
Note
The count starts from 1, not from 0. As mentioned above, counting 3 means that the breakpoint is valid only when the program hits a breakpoint for the third time.
When the program needs to pause the program execution several times after the program runs through a breakpoint to check variables, step-by-step debugging code, or execute other debugging tasks, you can use the Count breakpoint.
Note
The conditional breakpoint slows down the execution of the program, because every time a conditional breakpoint is hit, the conditional breakpoint must be evaluated. During debugging, if the program runs slowly, you can check the breakpoint list to see if there are unnecessary conditional breakpoints.
Note
Users can flexibly use conditional breakpoints to slow down program execution. If you want a program to run at a low speed for viewing, you can set one or more conditional breakpoints in the code segment. If you set the breakpoint condition to a condition that is never valid, program execution slows down, but does not stop.
Run the run to cursor command at the cursor)
Another debugging command is worth mentioning:Run to cursor"Command, you can select this command from the main menu [run | run to cursor. When"Run to cursorWhen running the program, the program stops running on the source code line that contains the editing cursor, as if the code line has a breakpoint. For example:
"Run to cursor"Can be used as a temporary breakpoint. When you want to check the source code of a line immediately, you do not need to set a breakpoint on the line; you only need to move the cursor to this line, and then select"Run to cursor"(Or pressF4Key), the debugger will pause program execution when the program is running to this line. It's like a breakpoint is set on this row. Use"Run to cursorThe advantage is that after debugging a piece of code, you do not have to clear the breakpoint.
All of the above tests are passed in Delphi7.