IDebugListeners.Add

Syntax

Add(Listener: IDebugListener);

Parameters

Listener - element that is used to track debugging information.

Description

The Add method adds an element that is used to track debugging information.

Example

Executing the example requires a form. The form contains two components: a Button and a Memo-field.

The full unit code is as follows:

Class Listener: Object, IDebugListener
    _Mem: IMemo;

    Public Constructor Create(ListMem: IMemo);
    Begin
        _Mem := ListMem;
    End Constructor Create;
    
    Public Sub Fail(Message: String);
    Begin
        _Mem.Lines.Add("Error: " + Message);
    End Sub Fail;
    
    Public Sub Write(Text, Cat: String);
    Begin
        _Mem.Lines.Add("Message: " + Text + " | " + Cat);
    End Sub Write;
End Class Listener;

Class TestForm: Form
    Memo1: Memo;
    Button1: Button;
    List: IDebugListener;

    Sub TestFormOnShow(Sender: Object; Args: IEventArgs);
    Begin
        Memo1.Lines.Clear;
    End Sub TestFormOnShow;
    
    Sub Button1OnClick(Sender: Object; Args: IEventArgs);
    Begin
        List := New Listener.Create(Memo1);
        Debug.Listeners.Add(List);
        Debug.Assert(True);
        Debug.Assert(False);
        Debug.AssertMsg(True"Msg True");
        Debug.AssertMsg(False"Msg False");
        Debug.Fail("MessageError");
        Debug.WriteLine("WriteLine");
        Debug.WriteLineIf(True"Writeline True");
        Debug.WriteLineIf(False"Writeline False");
    End Sub Button1OnClick;
    
    Sub TestFormOnClose(Sender: Object; Args: IEventArgs);
    Begin
        Debug.Listeners.Remove(List);
    End Sub TestFormOnClose;
End Class TestForm;

After executing the example, when a button is clicked, an element that is used to display debugging information to the Memo1 component, will be created. Error messages will be displayed, using the Fail method, others will be displayed using the Write method.

See also:

IDebugListeners