Delphi Depth Exploration - Codesite Application Guide

zhaozj2021-02-08  359

Delphi Depth Exploration - Codesite Application Guide

Although Delphi provides us with extremely powerful debugging features, finding BUG is still a daunting job, usually we write code and debug code consumes approval, and even more. In order to reduce the waste of unnecessary time and energy, sometimes we need a professional commissioning tool to help improve the efficiency of locking bugs. In this article we will introduce the famous debugging tool Codesite Pro 2.0 (which obtained the second name of the Best Debug Tool Award for 2000 Delphi Informant Reader). Its official website is www.raize.com.

The main function of Codesite is to allow the developer to use code to send a detailed information to a special receiver for further analysis. More precisely, through the TCODesite class implemented by Codesite, we can pack and send runtime information to CodeSite Dispatcher, which can route these messages to one or more receivers. The default information receiver is a Codesite Viewer.

The efficiency of Codesite is reflected in the dialog box that is different from simple display messages or sets breakpoints. It is more similar to the event log function with Delphi, of course, there is no doubt that it is more powerful than Event LOG. Many, its message is sustainable, that is, can be saved, easy to travel back.

Let's take a look at its three components before introducing the specific use of Codesite.

Codesite object

As mentioned earlier, sending a Codesite message from the running application is done by using a TCODESITE class (defined in the CSINTF unit), we can send the message as long as we simply call the TCODesite class. Give Codesite Dispatcher. For example, you can use the SENDMSG method of the object to send a simple string message. The TCODesite object enables a large number of ways to support various types of information transmission without any data conversion, such as the SENDObject method of the object has two parameters: one is a message string, one is a reference to the object instance, this method gets an object All published properties, then packed the information of these properties into the message of CODESite.

Codesite Dispatcher

In most cases, Codesite Dispatcher will quietly run in the system's tray area. Its unique function is a message from the Codesite from each TCODESite object to their destination. When default, the Codesite message will be sent to the Codesite Viewer. We don't even need to launch Codesite Dispatcher because it will be automatically started by objects such as TCODESITE.

The TCODESITE class defines a DestinationDetails property that allows developers to set the version of the Codesite message to be routed by Codesite Dispatcher to different destinations, such as log files. But usually there is no need to modify this property.

Codesite viewer

Although Codesite supports sending messages to different goals, the Codesite Viewer is the primary send target in most cases. Even if you send it to other objectives, such as log files or other machines, Codesite Viewer is still the main tool for viewing analysis messages.

Codesite View is composed of four panels below: Message list, message viewer, call stack and scratch panel. The main work area of ​​the Codesite View is a list of Message, which is used to display all messages sent to the Viewer or the messages loaded from the log file. The message viewer is used to view additional information associated with the message. For example, if the current message is sent by the SendObject method, the message viewer displays the current value of the total PUBLISED attribute of the object.

The calling stack panel will display a stack view according to the CSMENTERMETHOD message.

The Scratch panel is used to display non-sustainable information. When we want to track certain information, don't want to record them in the message log, such as when we want to look at the current and repetitive messages like the current location of the mouse, the SCRAT panel is very useful. At this time we can use the WritePoint method of the TCODESITE object and specify the LINE ID parameter to specify the number of Scratch panels used to accommodate mouse information.

Let's use a simple example to demonstrate how to send messages from the program to Codesite Viewer:

(1) Create a new project, then switch the component panel to the CODESITE page (the two components TCSGLOBALOBJECT and TCSObject are installed after the Codesite installation will be installed. Select the TCSGlobalObject component and place it on the form. The TCSGlobalObject component provides interactions for global Tcodesite objects when designing (global Tcodesite is initialized in the CSINFT unit).

(2) Add a button, then write down the following code in its OnClick event:

// CODESite is the global TCODESITE object

Codesite.sendmsg (the first message of 'Codesite);

(3) Compile and run this simple program. Click the button after running, Codesite Dispatcher and Codesite Viewer will run. At the same time, in the message list of Codesite View, you will see the message issued (Note: We don't have to start Codesite Dispatcher and Codesite View before running, because the Tcodesite object will automatically start them when you need to send messages). The results shown in Figure 4.38 below:

Figure 4.38

(4) Next, stop the program, add the following code during the OnClick event processing:

Codesite.sendObject ('Form1', Form1);

(5) Re-build the running program, then click the button once, this time you will see two messages in the Codesite Viewer. The message corresponding to the Form1 includes object information of FORM1.

(6) In order to see the associated object information of Form1, the menu command for the CODESITE VIEWER will display a new panel on the right side of the message list, and the PublisHed attribute of Form1 is displayed, as shown in Figure 4.39. :

Figure 4.39

(7) Stop the program again, then modify the code during the onclick process as follows:

Codesite.Entermethod ('Button1Click');

Codesite.sendmsg (the first message of 'Codesite);

Codesite.sendObject ('Form1', Form1);

CODESITE.EXITMETHOD (8) This time we run the program to click the button, you will see the "CODESite's first message" and "form1" message is indented between the "Button1Click" message. , As shown in Figure 4.40 below:

Figure 4.40

By adding the Call for Entermethod and ExitMethod methods, we can generate a log to log how to be called.

After seeing an example, we will find that the functionality of Codesite is very powerful. We can generate very detailed information as long as you add a few statements in the program, and you can show vivid charts via Codesite Viewer. Next, let's talk about the advanced application technology of CODESite.

Send a message to the log file

Every program will have more or less, not at this time, it will happen at that time, do not take it in a short time, it may episode for a long time, sometimes repeated, sometimes very casual, can be found. If a person tells you that there is no problem at all times, he must be lying. It is because of the incidentality and concealment of bugs, it is often difficult for us to repeat the BUG submitted by users, which gives us a great obstacle to our debugging procedure and find the problem, and Codesite can send the characteristics of the message to the log file. Just make the user report BUG easier, they can submit the information file generated by the runtime. The corresponding we will make more work more easily, we can use the Codesite Viewer to discuss the causes and location of the error occurred.

To change the target of the message, we can implement it by setting the DestinationDetails property of the Tcodesite object. This feature requires the customer's machine to install Codesite Dispatcher, which belongs to the part of free distribution in Codesite. The following should be told that the specific process is still based on the previous example:

(1) Add the following code to the oncreate event:

Codesite.DestinationDetails: = 'file [pat = c: /firstlog.csl]';

(2) Compile and restrain the program, this time after we click on the button, the message will no longer be sent to the CodeSite Viewer but send it to the firstLog.csl file of the C drive.

(3) Use the Codesite Viewer to load the firstLog.csl file, this time we look at the saved Codesite message like previously.

(4) If we want to send a message to the Codesite Viewer and log files simultaneously, only the previous code is:

Codesite.DestinationDetails: = 'Viewer, file [pat = c: /firstlog.csl]';

Send user customized data

Although the TCODesite class provides a large number of methods for processing different data types, sometimes we may need to send data information in a custom format. To this end, the TCODESITE class defines the SendCustomData method, which supports the sending arbitrary data type and will format the data according to a custom formatter so that the Codesite Viewer can display data correctly.

First we need to create a subclass of a TCSFormatter object, then overload the object's FormatData, InspectORTYPE, and TYPENAME methods. Then call the CODESITE object manager object CsObjectManager to register the new TCSFormatter subclass. In addition, we also need to call the RegisterCustomMAT method to register a new message type. The following is an example of a practical application, and a TcSemPloyeeeee.PAS implements a custom formatter of the TcSemPloyeeRecord record type:

UNIT CSEMPLOYEE

Interface

Uses

Windows, Graphics, Csintf;

Const

CSMemPloyeesummary = CSMUSER 1;

csmemployeedetails = csmuser 2;

First add a reference to the CSINTF unit to the USES section. The second step is to define a new CODESite message type constant for each format. We have defined two constants, pay attention to constants should be greater than CSMuser, but cannot be 32,000.

Type

TcSemPloyee = Record

Lastname: String;

Firstname: String;

Address: String;

CITY: STRING;

StRING;

ZIPCode: String;

Phonenumber: String;

HIREDATE: TDATETIME;

Salary: currency;

VacationDays: integer;

SICKDAYS: Integer;

Manager: boolean;

END;

The above record is the custom data type we have to send.

Tcsemployeesummaryformatter = Class (tcsformatter)

public

Function InspectORTYPE: TCSINSPECTORTORTYPE; OVERRIDE

Procedure formatdata (var data); OVERRIDE;

Function Typename: String; Override;

END;

Tcsemployeedetailsformatter = Class (TCSFormatter)

public

Function InspectORTYPE: TCSINSPECTORTORTYPE; OVERRIDE

Procedure formatdata (var data); OVERRIDE;

Function Typename: String; Override;

END;

The above is the definition of two custom formatters. The first format will format the TcSemPloyee record into a text format, and the second formatter will format the TcSemPloyee record into a grid style.

IMPLEMENTATION

Uses

Sysutils;

{======================================================================}

{== TcSemPloyeesumMaryFormatter methods ==}

{=================================================================================================================================================================================================================================================================================================00.

Begin

Result: = itstockstringlist;

END;

The first step in implementing a custom formatter is to determine which type of built-in viewer will be used to view the formatted data, where the character string column is used here. The type of view will be used by the formatdata method.

Procedure tcsemployeesummaryformatter.formatdata (var data);

VAR

EmpRec: tcsemployee;

Begin

EmpRec: = TcSemPloyee (DATA);

AddLine (EmpRec.firstname ' Emprec.lastname);

AddLine (Emprec.Address);

AddLine (EmpRec.city ',' EmpRec.State ' EmpRec.zipcode);

AddLine ('');

AddLine ('Phone:' EmpRec.phonenumber);

AddLine ('Hire Date:); EmpRec.hiRedate);

AddLine ('Salry:' Format ('% M', [EmpRec.salary]);

AddLine ('');

AddLine ('Vacation Days:' INTOSTOSTR (EMPREC.VACATIONDAYS);

Addline ('Sick Days:' INTOSTOSTR (EMPREC. SickDays);

IF EmpRec.manager then

AddLine ('Manager: YES')

Else

AddLine ('Manager: NO');

END;

The formatData method is the core part, pay attention to the DATA parameter that passes to the formatData method is a non-type variable parameter. This means that this parameter can be any data type, through the format registration process, we can ensure that the mandatory type is mapped to a customized data record without a conversion error.

After the conversion data type, we can format the data, here the addLine method of the TCSFormatter base class is formatted in the string to add a split line.

Function TCSemPloyeesummaryFormatter.Typename: String;

Begin

Result: = 'tcsemployee';

END;

The overload of the TypenAME method is optional, but usually we can use it to return a string displayed in the message list.

{=========================================} {== tcsemployeedetailsformatter methods == }

{======================================================================}

Function TCSemPloyeedetailsformatter.insPectorType: TCSINSPECTORTORTORTORTYPE

Begin

Result: = ItstockGrid;

END;

For the Employeedetails format, the named grid lookup will be used to view data information:

Procedure Tcsemployeedetailsformatter.Formatdata (VAR DATA);

VAR

EmpRec: tcsemployee;

Begin

EmpRec: = TcSemPloyee (DATA);

AddNameValuePair ('lastname', emprec.lastname);

AddNameValuePair ('firstname', EmpRec.firstname);

AddNameValuePair ('Address', EmpRec.Address);

AddNameValuePair ('City', EmpRec.city);

AddNameValuePair ('State', EmpRec.State);

AddNameValuePair ('Zipcode', EmpRec.zipcode);

AddNameValuePair ('Phonenumber', EmpRec.phonenumber);

AddNameValuePair ('HiRedate', EmpRec.hiredate);

AddNameValuePair ('Salary', Format ('% M', [EmpRec.salary]);

AddNameValuePair ('VacationDays', EmpRec.vacationDays);

AddNameValuePair ('SickDays', EmpRec.sickDays);

AddNameValuePair ('Manager', EmpRec.manager);

END;

Here, in order to format data in the grid viewer, we use the AddNameValuePair method to implement.

Function TCSemPloyeedetailsFormatter.Typename: string;

Begin

Result: = 'tcsemployee';

END;

The following two processes are used to encapsulate calls to the SendCustomData method, where the global TCODESITE object instance CODESite is called:

{=====================} {== support methods ==}

{=======================================}

Procedure CssendemPloyeesummary (const msg: string; Emprec: tcsemployee);

Begin

Codesite.sendcustomData (Csmemployeesummary, MSG, EmpRec);

END;

Procedure CssendemPloyeedetails (Const Msg: String; Emprec: TcSemployee);

Begin

Codesite.sendCustomData (Csmemployeedetails, MSG, EmpRec);

END;

Finally, don't forget to call the CSOBJECTMANAGER.REGISTERCUSTOMMATTER method to register the formatter to the Codesite Object Manager.

Initialization

CsObjectManager.RegisterCustomformatter (csmemployeesummary,

Tcsemployeesummaryformatter;

CsObjectManager.RegisterCustomformatter (csmemployeedetails,

Tcsemployeedetailsformatter;

End.

In addition to the characteristics of the features, Codesite also supports remote debugging, that is, the message can be routed to a log file on a remote machine or on the Code Viewer. Because we rarely use this feature, it will not be discussed in detail here.

转载请注明原文地址:https://www.9cbs.com/read-806.html

New Post(0)