Non Gamstop Betting SitesNon Gamstop CasinosBest Casinos Not On GamstopNon Gamstop CasinoCasino Not On Gamstop

Debug Tips
(AfxMessageBox / Trace / Break / Assert)


Once the code has been written the finished application must be built this may be done by clicking on Build/Build filename.exe - the accelerator key for this is F7.

This application should be run in debug mode, this may be done by clicking on Build/Start Debug/Go - the accelerator key for this is F5.

If the application fails to run properly then it must be debugged. Tips on how to do this are as follows :

AfxMessageBox

Commands may be inserted into the application which indicate when a line of code is executed. Consider the following code :

void CNamesDoc::OnAddVariables()
{

AddVariables();

}

An AfxMessageBox may be inserted into this code - every time it is executed a pop-up message will display :

void CNamesDoc::OnAddVariables()
{

AfxMessageBox("AddVariables() function is called!");
AddVariables();

}

Below is an image of this displayed pop-up message :

TRACE

One feature of an AfxMessageBox is that it stops the program until the OK button is clicked. The TRACE command performs a similar task but simply displays the message in the debug window. (The debug window is displayed at the bottom of the screen when the program is executed in debug mode). An example of using the TRACE command is shown below.

for( int nNumber = 1; nNumber <= 10; nNumber++ )
{

// some important code may be executed here

CString strTemp;
strTemp.Format("%d", nNumber);
TRACE("nNumber = " + strTemp + "\n");

}

This would produce the following output in the debug window.

Break

The code in an application may also be executed 'step by step'. This option is most frequently carried out after a break has been inserted into the code. This may be done by positioning the cursor on a line of code and clicking on the button on the toolbar displaying an upturned hand - the accelerator key for this is F9. This will insert a break in the code as shown in the image below :

Pressing F10 allows the code to be executed 'step by step' from this break point onwards. In addition clicking View/Debug Windows/Variables allows the values of recent variables to be displayed in an additional debug window.

Assert

In debug mode an ASSERT checks that a statement is true. An example of this is shown in the code below :

double nTop = 3.5;
double nBottom = 7.1;
double nAnswer = nTop/nBottom;

ASSERT(nAnswer == 0.5);

This program will terminate when it gets to the ASSERT as the statement is not true. This application can then be debugged.


Click here to return to menu

Worth your time