Page 1 of 1

I can't stop XModifyListener with removeModifyListener !

Posted: Sat Dec 08, 2007 10:25 pm
by onidarbe
Why do I get "Basic runtime error. Object variable not ser." when I execute "Sub Stop_Listener" ?
I did use Global on both used variable's !

Code: Select all

Global oListener As Object
Global oListenerRange As Object
Sub Start_Listener   ' this sub is automaticly started on document-open
	oListenerRange=thisComponent.sheets(0)
	oListener = CreateUnoListener("Listener_","com.sun.star.util.XModifyListener")
	oListenerRange.addModifyListener(oListener)
End Sub
Sub Stop_Listener
	oListenerRange.removeModifyListener(oListener)
End Sub
Sub Listener_Disposing(oEvent)
End Sub 
Sub Listener_Modified(oEvent)
	msgbox("Some cell has changed.")
End Sub

Global Variables get lost while programming !

Posted: Tue Dec 11, 2007 11:02 pm
by onidarbe
Seems Global variables lose there contense as soon as one alters the programming !!! Is there any way to keep them?
Otherwise I can't stop a event-listener because repointing to the same objects as shown here behind the REM, don't work.
I guess I lose contact with the excecuted "addModifyListener" as soon as I edit some other macro's.

Global oListener As Object
Global oListenerRange As Object
Sub Start_Listener
oListenerRange=thisComponent.sheets(0)
oListener = CreateUnoListener("Listener_","com.sun.star.util.XModifyListener")
oListenerRange.addModifyListener(oListener)
End Sub
Sub Stop_Listener
REM oListenerRange=thisComponent.sheets(0)
REM oListener = CreateUnoListener("Listener_","com.sun.star.util.XModifyListener")
oListenerRange.removeModifyListener(oListener)
End Sub
Sub Listener_Modified(oEvent)
msgbox("Some cell has changed.")
End Sub