I can't stop XModifyListener with removeModifyListener !

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
onidarbe
Posts: 84
Joined: Thu Nov 29, 2007 8:03 pm
Location: Belgium, Mechelen

I can't stop XModifyListener with removeModifyListener !

Post 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
OOo 3.1.X on Ms Windows XP
User avatar
onidarbe
Posts: 84
Joined: Thu Nov 29, 2007 8:03 pm
Location: Belgium, Mechelen

Global Variables get lost while programming !

Post 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
OOo 3.1.X on Ms Windows XP
Post Reply