⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch10.htm

📁 delphi自学的好教材!特别适合刚刚起步学习delphi的人员!同样对使用者具有参考价值!
💻 HTM
📖 第 1 页 / 共 5 页
字号:
	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Evaluate/Modify</TD>		<TD ALIGN="LEFT">Ctrl+F7</TD>		<TD ALIGN="LEFT">Displays the Evaluate/Modify dialog box.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Add Watch</TD>		<TD ALIGN="LEFT">Ctrl+F5</TD>		<TD ALIGN="LEFT">Displays the Watch Properties dialog box.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Add Breakpoint</TD>		<TD ALIGN="LEFT">None</TD>		<TD ALIGN="LEFT">Displays a submenu that contains items to add a source, address, data, or module			load breakpoint.</TD>	</TR></TABLE></P><P>You will use these menu items a lot when you are debugging your programs. Youshould also become familiar with the various keyboard shortcuts for the debuggingoperations. Now let's take a look at breakpoints and how to use them in your program.</P><P><H2><A NAME="Heading3"></A>Using Breakpoints</H2><P>When you run your program from the Delphi IDE, it runs at full speed, stoppingonly where you have set breakpoints.</P><P><strong>New Term:</strong> A <I>breakpoint</I> is a marker that tells the debugger topause program execution when it reaches that place in the program.</P><P><H3><A NAME="Heading4"></A>Setting and Clearing Breakpoints</H3><P>To set a breakpoint, click in the editor window's gutter to the left of the lineon which you want to pause program execution (the gutter is the gray margin alongthe Code Editor window's left edge). The breakpoint icon (a red circle) appears inthe gutter and the entire line is highlighted in red. To clear the breakpoint, clickon the breakpoint icon and the breakpoint is removed. You can also press F5 or chooseToggle Breakpoint from the Code Editor context menu to toggle a breakpoint on oroff.</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> A breakpoint can be set only on a line that generates actual code.	Breakpoints are not valid if set on blank lines, comment lines, or declaration lines.	You are not prevented from setting a breakpoint on these types of lines, but the	debugger warns you if you do. Attempting to set a breakpoint on any of the following	lines will produce an invalid breakpoint warning: 	<PRE>{ This is a comment followed by a blank line. }X : Integer;  { a declaration }</PRE></BLOCKQUOTE><PRE></PRE><BLOCKQUOTE>	<P>Breakpoints <I>can</I> be set on a function or procedure's end statement. <HR></BLOCKQUOTE><P>If you set a breakpoint on an invalid line, the Code Editor will display the breakpointin green (assuming the default color scheme) and the breakpoint icon in the gutterwill be grayed.</P><P>When the program is run under the debugger, it behaves as it normally would--untila breakpoint is hit, that is. When a breakpoint is hit, the IDE is brought to thetop and the breakpoint line is highlighted in the source code. If you are using thedefault colors, the line where the program has stopped is highlighted in red becausered indicates a line containing a breakpoint.</P><P><strong>New Term:</strong> The <I>execution point</I> indicates the line that will beexecuted next in your source code.</P><P>As you step through the program, the execution point is highlighted in blue andthe editor window gutter displays a green arrow glyph. Understand that the line highlightedin blue has not yet been executed but will be when program execution resumes.</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> The current execution point is highlighted in blue unless the line	containing the execution point contains a breakpoint. In that case, the line is highlighted	in red. The green arrow glyph in the gutter is the most accurate indication of the	execution point because it is present regardless of the line's highlighting color.	<HR></BLOCKQUOTE><P>When you stop at a breakpoint, you can view variables, view the call stack, browsesymbols, or step through your code. After you have inspected any variables and objects,you can resume normal program execution by clicking the Run button. Your applicationwill again run normally until the next breakpoint is encountered.</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> It's common to detect coding errors in your program after you have	stopped at a breakpoint. If you change your source code in the middle of a debugging	session and then choose Run to resume program execution, the IDE will prompt you	with a message box asking whether you want to rebuild the source code. If you choose	Yes, the current process will be terminated, the source code will be recompiled,	and the program will be restarted.<BR>	</P>	<P>The problem with this approach is that your program doesn't get a chance to close	normally, and any resources currently in use might not be freed properly. This scenario	will almost certainly result in memory leaks. Although Windows 95 and Windows NT	handle resource leaks better than 16-bit Windows, it is still advisable to terminate	the program normally and then recompile it. <HR></BLOCKQUOTE><H3><A NAME="Heading5"></A>The Breakpoint List Window</H3><P>The Delphi IDE keeps track of the breakpoints you set. These breakpoints can beviewed through the Breakpoint List window. To view the breakpoint list, choose View|DebugWindows|Breakpoints from the main menu. The Breakpoint List window is displayed asshown in Figure 10.1.</P><P><A HREF="javascript:popUp('28671001.gif')"><B>FIGURE 10.1.</B></A><B> </B><I>TheBreakpoint List window.</I></P><P>The Breakpoint List window has four columns:</P><UL>	<LI>The Filename/Address column shows the filename of the source code unit in which	the breakpoint is set.	<P>	<LI>The Line/Length column shows the line number on which the breakpoint is set.	<P>	<LI>The Condition column shows any conditions that have been set for the breakpoint.	<P>	<LI>The Pass column shows the pass count condition that has been set for the breakpoint.	(Breakpoint conditions and pass count conditions are discussed in the section &quot;Conditional	Breakpoints.&quot;)</UL><P>The columns can be sized by dragging the dividing line between two columns inthe column header.</P><P><strong>NOTE:</strong> The Pass column doesn't show the number of times the breakpointhas been hit; it only shows the pass condition that you have set for the breakpoint.</P><P><H4>Breakpoint List Context Menus</H4><P>The Breakpoint List window has two context menus. Table 10.3 lists the contextmenu items you will see when you click the right mouse button over any breakpoint.I will refer to this as the window's <I>primary context menu</I>.</P><P><H4>TABLE 10.3. THE PRIMARY BREAKPOINT LIST CONTEXT MENU.</H4><P><TABLE BORDER="1">	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"><I>Item</I></TD>		<TD ALIGN="LEFT"><I>Description</I></TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Enable</TD>		<TD ALIGN="LEFT">Enables or disables the breakpoint. When a breakpoint is disabled, its glyph is grayed			out in the Breakpoint List window. In the source window, the breakpoint glyph is			also grayed, and the breakpoint line is highlighted in green to indicate that the			breakpoint is disabled.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Delete</TD>		<TD ALIGN="LEFT">Removes the breakpoint.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">View Source</TD>		<TD ALIGN="LEFT">Scrolls the source file in the Code Editor to display the source line containing			the breakpoint. (The Breakpoint List retains focus.)</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Edit Source</TD>		<TD ALIGN="LEFT">Places the edit cursor on the line in the source file where the breakpoint is set			and switches focus to the Code Editor.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Properties</TD>		<TD ALIGN="LEFT">Displays the Source Breakpoint Properties dialog box.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Dockable</TD>		<TD ALIGN="LEFT">Determines whether the Breakpoint List window is dockable.</TD>	</TR></TABLE><BLOCKQUOTE>	<P><HR><strong>TIP:</strong> To quickly edit the source code line on which a breakpoint is set,	double-click on the breakpoint in the Filename column of the Breakpoint List window.	This is the same as choosing Edit Source from the Breakpoint List context menu. <HR></BLOCKQUOTE><P>The secondary context menu is displayed by clicking the right mouse button whilethe cursor is over any part of the Breakpoint List window that doesn't contain abreakpoint. This context menu has items called Add, Delete All, Disable All, EnableAll, and Dockable. These items are self-explanatory, so I won't bother to commenton them.</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> In my opinion, the Add context menu item isn't very useful. It is	much easier to set a breakpoint in the Code Editor than to add a breakpoint via the	Add command in the Breakpoint List window. <HR></BLOCKQUOTE><H4>Enabling and Disabling Breakpoints</H4><P>Breakpoints can be enabled or disabled any time you like. You disable a breakpointif you want to run the program normally for a while; you can enable the breakpointlater without having to re-create it. The debugger ignores breakpoints that are disabled.To enable or disable a breakpoint, right-click on the breakpoint in the BreakpointList window and toggle the Enable item on the context menu.</P><P><H4>Modifying Breakpoints</H4><P>If you want to modify a breakpoint, choose Properties from the primary BreakpointList context menu. When you do, the Source Breakpoint Properties dialog box is displayed(see Figure 10.2).</P><P><A HREF="javascript:popUp('28671002.gif')"><B>FIGURE 10.2.</B></A><B> </B><I>TheSource Breakpoint Properties dialog box.</I></P><P>The primary reason for modifying a breakpoint is to add conditions to it. (Conditionalbreakpoints are discussed in the section &quot;Conditional Breakpoints.&quot;)</P><P>To remove a breakpoint, select the breakpoint in the Breakpoint List window andthen press the Delete key on the keyboard. To delete all breakpoints, right-clickand then choose Delete All. Now let's take a look at the two breakpoint types: simpleand conditional.</P><P><H3><A NAME="Heading6"></A>Simple Breakpoints</H3><P>A <I>simple breakpoint</I> causes program execution to be suspended whenever thebreakpoint is hit. When you initially set a breakpoint, it is by default a simplebreakpoint. Simple breakpoints don't require much explanation. When the breakpointis encountered, program execution pauses and the debugger awaits your bidding. Mostof the time you will use simple breakpoints. Conditional breakpoints are reservedfor special cases in which you need more control over the debugging process.</P><P><H3><A NAME="Heading7"></A>Conditional Breakpoints</H3><P>In the case of a <I>conditional breakpoint</I>, program execution is paused onlywhen predefined conditions are met. To create a conditional breakpoint, first setthe breakpoint in the Code Editor. Then choose View|Debug Windows|Breakpoints fromthe main menu to display the Breakpoint List window. Right-click on the breakpointfor which you want to set conditions and choose Properties. When the Source BreakpointProperties dialog box is displayed, set the conditions for the breakpoint.</P><P>Conditional breakpoints come in two flavors. The first type is a <I>conditionalexpression breakpoint</I>. Enter the conditional expression in the Condition fieldof the Source Breakpoint Properties dialog box (refer to Figure 10.2). When the programruns, the conditional expression is evaluated each time the breakpoint is encountered.When the conditional expression evaluates to True, program execution is halted. Ifthe condition doesn't evaluate to True, the breakpoint is ignored. For example, lookback at the last breakpoint in the Breakpoint List window shown in Figure 10.1. Thisbreakpoint has a conditional expression of X &gt; 20. If at some point in the executionof the program X is greater than 20, the program will stop at the breakpoint. IfX is never greater than 20, program execution will not stop at the breakpoint.</P><P>The other type of conditional breakpoint is the <I>pass count breakpoint</I>.With a pass count breakpoint, program execution is paused only after the breakpointis encountered a specified number of times. To specify a pass count breakpoint, editthe breakpoint and specify a value for the Pass Count field in the Source BreakpointProperties dialog box. If you set the pass count for a breakpoint to 3, program executionwill stop at the breakpoint the third time the breakpoint is encountered.</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> The pass count is 1-based, not 0-based. As indicated in the preceding	example, a pass count of 3 means that the breakpoint will be valid the third time	the breakpoint is encountered by the program. <HR></BLOCKQUOTE><P>Use pass count breakpoints when you need your program to execute through a breakpointa certain number of times before you break to inspect variables, step through code,or perform other debugging tasks.</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> Conditional breakpoints slow down the normal execution of the program	because the conditions need to be evaluated each time a conditional breakpoint is	encountered. If your program is acting sluggish during debugging, check your breakpoint	list to see whether you have conditional breakpoints that you have forgotten about.	<HR></P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -