In this article:

General Information

Description

Debug Print in Fore.NET

Fore Example

Fore.NET Example

Debug Print

Article number: KB000003

General Information

Related blocks:

Description

The System system assembly has the Debug class used to display debug information when executing units or forms. This class has several static methods used to solve various problems:

The Assert method enables a developer to insert a condition into the code for checking the state of executed code. If the code does not satisfy the specified condition the system displays an appropriate message. Developers often write code for procedures and functions based on some assumptions on values of their parameters. This method enables a developer to include checking these assumptions in the code and find problems on testing stage if these problems really exist.

The Fail method allows reporting 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.

Debug Print in Fore.NET

To display the debug messages when working with the .NET assembly the development environment is modified in the way the methods and classes of the Debug class from the System.Diagnostics namespace could 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 the specified messages, are also display the information about the call stack). Description of all overloaded methods of the System.Diagnostics.Debug class is available in the MSDN.

Fore Example

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(0100));
    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

Fore.NET Example

To execute an example connect the .NET System and "mscorlib" assemblies. An example, 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(0100));
    Finally
        Debug.Unindent();
    End Try;
    Debug.Assert(Rnd.NextDouble() > 0.5Value 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:

Developers Knowledge Base