Hi all.

I am doing my first event handling in OOoBasic and I am doing this to track which cell a user has currently selected:

<CODE>
 Private SelectionChangeListener as Object

 Sub StartSelectionChangeListener
   if IsNull(SelectionChangeListener) then
SelectionChangeListener = CreateUnoListener("XSelectionChangeListener_",
       "com.sun.star.view.XSelectionChangeListener")
ThisComponent.CurrentController.AddSelectionChangeListener(SelectionChangeListener)
   end if
 End Sub

 Sub StopSelectionChangeListener
   if Not IsNull(SelectionChangeListener) then
ThisComponent.CurrentController.RemoveSelectionChangeListener(SelectionChangeListener)
     SelectionChangeListener = Nothing
   else
     MsgBox "LISTENER NOT STARTED"
   end if
 End Sub
</CODE>

If I first run StartSelectionChangeListener and then run StopSelectionChangeListener I get a message box because OOoBasic has reset the SelectionChangeListener variable to Nothing after exit of StartSelectionChangeListener (!). If I change the declaration of SelectionChangeListener to GLOBAL instead of PRIVATE it works as intended.

I wonder why this is so ? Because I also use PRIVATE module vars to hold dialog references, e.g.

<CODE>
 Private Dlg as Variant

 Sub ShowMyDialog
   Dlg = CreateUnoDialog(DialogLibraries.MyModule.MyDialog)
   Dlg.Execute
 End Sub

 Sub OnButtonClick
   MsgBox Dlg.Model.MyButton.Label & " was pressed."
 End Sub
</CODE>

and the result from CreateUnoDialog() survives after exit of ShowMyDialog and so the Dlg var is valid in the button event handler OnButtonClick. Why this difference ? I would prefer to use PRIVATE module vars instead of GLOBAL vars if I can.

Cheers
-- Jan Holst Jensen

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org

Reply via email to