CreateUnoListener Function

рд▓рд┐рд╕рдирд░ рдЗрдВрд╕реНрдЯреИрдВрд╕ рддреИрдпрд╛рд░ рдХрд░рддрд╛ рд╣реИ.

Many Uno interfaces let you register listeners on a special listener interface. This allows you to listen for specific events and call up the appropriate listener method. The CreateUnoListener function waits for the called listener interface and then passes the interface an object that the interface supports. This object is then passed to the method to register the listener.

Syntax:


oListener = CreateUnoListener( Prefixname, ListenerInterfaceName )

рдЙрджрд╛рд╣рд░рдг:

рдирд┐рдореНрди рдЙрджрд╛рд╣рд░рдг рдмреЗрд╕рд┐рдХ рд▓рд╛рдЗрдмреНрд░реЗрд░реА рд╡рд╕реНрддреБ рдкрд░ рдЖрдзрд╛рд░рд┐рдд рд╣реИ.


Dim oListener
oListener = CreateUnoListener( "ContListener_","com.sun.star.container.XContainerListener" )

The CreateUnoListener method requires two parameters. The first is a prefix and is explained in detail below. The second parameter is the fully qualified name of the Listener interface that you want to use.

The Listener must then be added to the Broadcaster Object. This is done by calling the appropriate method for adding a Listener. These methods always follow the pattern "addFooListener", where "Foo" is the Listener Interface Type, without the 'X'. In this example, the addContainerListener method is called to register the XContainerListener:


Dim oLib
oLib = BasicLibraries.Library1 ' Library1 must exist!
oLib.addContainerListener( oListener ) ' Register the listener

The Listener is now registered. When an event occurs, the corresponding Listener calls the appropriate method from the com.sun.star.container.XContainerListener Interface.

The prefix calls registered Listeners from Basic-subroutines. The Basic run-time system searches for Basic-subroutines or functions that have the name "PrefixListenerMethode" and calls them when found. Otherwise, a run-time error occurs.

рдЗрд╕ рдЙрджрд╛рд╣рд░рдг рдореЗрдВ рд▓рд┐рд╕рдирд░-рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рдирд┐рдореНрдирд▓рд┐рдЦрд┐рдд рд╡рд┐рдзрд┐рдпрд╛рдБ рдЗрд╕реНрддреЗрдорд╛рд▓ рдХрд░рддрд╛ рд╣реИ:

In this example, the prefix is ContListener_. The following subroutines must therefore be implemented in Basic:

An event structure type that contains information about an event exists for every Listener type. When a Listener method is called, an instance of this event is passed to the method as a parameter. Basic Listener methods can also call these event objects, so long as the appropriate parameter is passed in the Sub declaration. For example:


Sub ContListener_disposing( oEvent )
    MsgBox "disposing"
    MsgBox oEvent.Dbg_Properties
End Sub
 
Sub ContListener_elementInserted( oEvent )
    MsgBox "elementInserted"
    MsgBox oEvent.Dbg_Properties
End Sub
 
Sub ContListener_elementRemoved( oEvent )
    MsgBox "elementRemoved"
    MsgBox oEvent.Dbg_Properties
End Sub
 
Sub ContListener_elementReplaced( oEvent )
    MsgBox "elementReplaced"
    MsgBox oEvent.Dbg_Properties
End Sub

рдпрджрд┐ рд╡рд╕реНрддреБ рдХрд╛ рдЗрд╕реНрддреЗрдорд╛рд▓ рдирд╣реАрдВ рдХрд┐рдпрд╛ рдЧрдпрд╛ рд╣реИ рддреЛ рдШрдЯрдирд╛ рдХрд╛ рдкреИрд░рд╛рдореАрдЯрд░ рд╢рд╛рдорд┐рд▓ рдХрд░рдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рдЖрдкрдХреЛ рдирд╣реАрдВ рд╣реИ:


' Minimal implementation of Sub disposing
Sub ContListener_disposing
End Sub
Warning Icon

Listener methods must always be implemented to avoid Basic run-time errors.


Please support us!