In this article:
Article number: KB000003
Related blocks:
The System system assembly has the Debug class that is used to display debug information when executing units or forms. This class has several static methods that are used to solve various tasks:
Write, WriteLine. They are used to display the specified string. By default, all debug messages are displayed in the Console Window panel of the development environment.
WriteIf, WriteLineIf. They are used to display the specified string only when the specified condition is satisfied.
Indent, Unindent. They are used to display the specified string with an indent with respect to previous strings.
The Assert method enables the user to insert a condition to the code for checking the state of executed code. If the code does not satisfy the specified condition, an appropriate message is displayed. Developers often write code for procedures and functions based on some assumptions on values of their parameters. This method enables the user to include checking these assumptions in the code and find problems at testing stage if these problems really exist.
The Fail method enable the user to report a serious problem that arises during code execution.
Developers often use the IWinApplicationClass.InformationBox function to display debug messages. Its use can lead to the malfunctioning of application system web version. It is recommended to take this into account when developing application systems.
To display the debug messages when working with a .NET assembly the development environment is modified in the way the methods and classes of the Debug class from the System.Diagnostics namespace can be used (the System.dll assembly). Properties and methods of the Debug class from the Fore System assembly in the Fore.NET are not supported.
Setting of all properties and methods of specified classes is almost the same. There are some differences with the Assert and Fail methods: these methods of the System.Diagnostics.Debug class, except for the specified messages, also display the information about the call stack). Description of all overloaded methods of the System.Diagnostics.Debug class is available in the MSDN.
Sub UserProc;
Var
Value: Double;
Begin
Debug.WriteLine("Hello, world!");
Value := Math.Rand;
Debug.Write("Random value: "); Debug.WriteLine(Value);
Debug.WriteLineIf(Value > 0.5, "Random value is greater than 0.5");
Debug.WriteLine("Indented random outputs");
Debug.Indent;
Try
Debug.WriteLine(Math.Rand);
Debug.WriteLine(Math.RandBetween(0, 100));
Finally
Debug.Unindent;
End Try;
Debug.Assert(Math.Rand > 0.5);
Debug.Fail("There is an serious failure in software");
End Sub UserProc;
The console window displays the following:
Unit execution is started
Hello, world!
Random value: 0,175467571750159
Indented random outputs
0,64320357647799
11,6849231109221
Assert failed
There is an serious failure in software
Unit execution finished
To execute the example, add links to the System and mscorlib .NET assemblies. An example that is similar to the example on the Fore will look as follows:
Imports System;
Imports System.Diagnostics;
Public Shared Sub Main(Params: StartParams);
Var
Rnd: Random = New Random();
Value: Double;
Begin
Debug.WriteLine("Hello, world!");
Value := Rnd.NextDouble();
Debug.Write("Random value: "); Debug.WriteLine(Value);
Debug.WriteLineIf(Value > 0.5, "Random value is greater than 0.5");
Debug.WriteLine("Indented random outputs");
Debug.Indent();
Try
Debug.WriteLine(Rnd.NextDouble());
Debug.WriteLine(Rnd.Next(0, 100));
Finally
Debug.Unindent();
End Try;
Debug.Assert(Rnd.NextDouble() > 0.5, Value less than 0.5).
Debug.Fail("There is an serious failure in software");
End Sub;
The console window displays the following:
Hello, world!
Random value: 0,52850199561962
Random value is greater than 0.5
Indented random outputs
0,832817622382575
95
---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
Value less than 0.5
---- Assert Long Message ----
...Next is the call stack...
---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
There is an serious failure in software
---- Assert Long Message ----
...Next is the call stack...
See also: