Debug Checker (the debug Inspector)
Debug Inspector enables users to view data objects such as classes and records, and can also be used to view simple data types such as integers, character arrays, but such simple data types are best viewed with watch list. The maximum purpose of Debug Inspector is to view classes and records.
Note
Debug Inspector can only be used when a program running under the debugger pauses execution.
To view an object, click the name of the object in the Code Editor and select the "Inspect" menu item from the shortcut menu in Code Editor or press "Alt + F5", or select "Run | from the main menu. Inspect ... "menu item.
The Debug inspector window contains details about the selected object. If you are viewing an object with a simple data type, the Debug inspector window first displays its current value (in both decimal and hexadecimal formats), and the status line at the bottom of the window displays its data type. For example, to view an integer variable, the value of the variable is displayed and "Integer" is displayed on the status line. At the top of the Debug inspector window is a combo box that contains a description of the object being viewed.
If you check a class with Debug inspector, the Debug inspector window looks like this:
To better understand the debug Inspector, follow these steps:
1) load the previously created debugtest program, download:watchlist test program. RAR
2) set a breakpoint at a location in the Watchbtnclick method. Such as:
3) Run the program and click the Watch Test button. The debugger stops at the breakpoint at the setting.
4) From the main Menu "Run | Inspect ... "Displays the Inspect dialog box.
5) Enter self in the Expression field and click OK.
6) The Debug inspector is displayed, at which time the user can check the main form data.
Note
Self can only be viewed from within a method of a class. If you accidentally set a breakpoint in a regular function or procedure and try to view self, the system displays an error message telling the user that self is an illegal symbol. such as error message:
In the example above, self is the main form of the application.
Debug Inspector page (debug Inspector pages)
In order to explain the various parts of the Debug Inspector page in detail, we will first design a simple class with the following steps:
1) Select the main Menu "File | New | Other ", select Console application(console program) and create a new console program;
2) Create a parent class animal and subclass dog; The following code:
12345678910111213141516171819202122232425262728293031 |
program DebugInspectorPage;
{$APPTYPE CONSOLE}
uses
SysUtils;
type
TAnimal = class
Name: string;
end;
TDog = class(TAnimal)
Color: string;
procedure Say();
end;
var
Dog: TDog;
{ TDog }
procedure TDog.Say;
begin
Writeln(‘汪汪...‘);
end;
begin
Dog := TDog.Create;
Dog.Name := ‘小黄‘;
Dog.Color := ‘黄色‘;
Dog.Say;
Dog.Free;
end.
|
3) Then set a breakpoint before end, such as:
4) Save the program, save the project as DEBUGINSPECTORPAGE.DPR; Next Run the program, after stopping at the breakpoint, select "Run | Inspect ", adding a dog variable;
5) The Debug Inspector page is displayed, such as:
The data page shows both the parent class and the child class, and if the user only wants to see the information of the subclass, right-click on the "Show inherited" menu item in the popup menu.
Tick off the following as:
6) If you want to view a data member further, you can double-click the Value field of the row in which the data member is located, and a second Debug inspector window will open, displaying the selected data member. Multiple debug inspector Windows can be opened at the same time.
7) Debug Inspector Method page displays the methods of the class. In some cases, the Method tab is not displayed (when viewing a simple data type is displayed). The status bar displays the declaration of the selected method. As follows:
8) The Properties page of the Debug inspector displays the attributes of the class being viewed. Viewing the properties of a class is of little value (the information provided is of no special use). Most of the time, viewing data members that are related to a property on the database page satisfies the user's needs.
Note
The Debug Inspector Method page and the Properties page are only valid when the user checks the class. When checking the simple data type, the value displays the data page.
Tip
If the user wants the Debug inspector window to always be on top of code editor, go to the main menu "Tools | Debugger Options ... on the General page of the Debugger Options dialog box, select the Inspectors stay on top check box. Such as:
Debug Inspector shortcut menu (Debug Inspector context Menus)
The Debug inspector window also has a shortcut menu that users can use when they view the data object in Debug Inspector.
For example, a user can right-click and select the Descend menu item from the shortcut menu to replace the current object in the Debug inspector window with the selected object without having to open a Debug inspector window for each object.
For example, to view a form with the Button1 button, select Button1 in the Debug inspector and select the "Descend" item from the shortcut menu or press the "Ctrl+d" key to debug Inspector is going to look at the Button1 object. The benefit of this is that the IDE logs all objects that have been viewed, and if you want to go back to the object you've viewed, simply select the object from the combo box at the top of the Debug inspector window.
The "Change" menu item is used to vary the value of a variable.
Note
Be especially careful when changing the value of a variable with debug inspector. Once you change the data member incorrectly or specify an illegal value for a data member, it can cause the program to fail.
The "Inspect" menu item allows the user to open a Debug inspector window again, displaying the object currently selected by the cursor.
The "New Expression" menu item allows the user to enter a new expression to be checked in the debug inspector.
The "Show inherited" menu item determines how much information the Debug inspector displays. When show inherited is selected, Debug Inspector displays all data members, methods, and properties of the checked class, as well as data members, methods, and properties inherited from the ancestor class. When show inherited is not selected, only data members, methods, and properties that are checked for the class itself are displayed. Turning off this menu item can speed up the debug inspector because you don't need to display that much information.
Tip
If a user forgets the type of a data member in a class, you can click the data member when the program pauses on the breakpoint and press ALT + F5 to display the debug Inspector. The bottom status bar of the Debug inspector window displays the data type of the data member.
The above code is tested in Delphi7 and the code is downloaded: debuginspector page description. rar
Commissioning of the Delphi Application (iv) the debug Inspector