CreateUnoListener Function [Runtime]/text/sbasic/shared/03132000.xhpSun Microsystems, Inc.converted from old format - fpe
dedr: fixed #i31078#CreateUnoListener functionCreateUnoListener Function [Runtime]Creates a Listener instance.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 )Example:The following example is based on a Basic library object.Dim oListeneroListener = 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 oLiboLib = BasicLibraries.Library1 ' Library1 must exist!oLib.addContainerListener( oListener ) ' Register the listenerThe 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 Listener-Interface uses the following methods:disposing:Listener base interface (com.sun.star.lang.XEventListener): base interface for all Listener InterfaceselementInserted:Method of the com.sun.star.container.XContainerListener interfaceelementRemoved:Method of the com.sun.star.container.XContainerListener interfaceelementReplaced:Method of the com.sun.star.container.XContainerListener interfaceIn this example, the prefix is ContListener_. The following subroutines must therefore be implemented in Basic:ContListener_disposingContListener_elementInsertedContListener_elementRemovedContListener_elementReplacedAn 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_PropertiesEnd SubSub ContListener_elementInserted( oEvent )MsgBox "elementInserted"MsgBox oEvent.Dbg_PropertiesEnd SubSub ContListener_elementRemoved( oEvent )MsgBox "elementRemoved"MsgBox oEvent.Dbg_PropertiesEnd SubSub ContListener_elementReplaced( oEvent )MsgBox "elementReplaced"MsgBox oEvent.Dbg_PropertiesEnd SubYou do not need to include the parameter of an event object if the object is not used:' Minimal implementation of Sub disposingSub ContListener_disposingEnd SubListener methods must always be implemented to avoid Basic run-time errors.