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.