Hello,
First, it is not apparent why you just don’t use the Text modified
event in the properties of the date control. Just point directly to your macro.
However, if you are intent on creating a listener, hopefully you have reviewed the topic in OOME (by Pitonyak). If not, you can get PDF here → OOME PDF. See section 10.12. UNO listeners
on page 252 for info. Also, in my answer on this post → How to properly code a broadcaster and listener in LO Basic, I have copied some necessary code from OOME & also created a Key Handler.
Your listener is missing a few key elements. Using the Pitonyak code produces the following methods for com.sun.star.beans.XPropertyChangeListener
:
SbxEMPTY queryInterface ( SbxOBJECT )
SbxVOID disposing ( SbxOBJECT )
SbxVOID propertyChange ( SbxOBJECT )
queryInterface
can be ignored but the other two are necessary along with a method to start (this you have) and a method to stop the listener. All necessary methods should be included even if they contain nothing. You had the propertyChange
method but not the disposing
method. Another missing element is for the listener to be in a global variable to verify if it is active or not.
Here are the working methods I have created based upon your code:
global oListener as object
Sub test()
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
oForm = oSheet.drawPage.getForms().getByIndex(0)
oDateField = oForm.getByName("DateField1")
oListener = createUnoListener("Event_", "com.sun.star.beans.XPropertyChangeListener")
REM Changed to just look for modified Text
oDateField.addPropertyChangeListener("Text",oListener)
End Sub
Sub sStopTest
if not IsNull(oListener) then 'only if still running'
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
oForm = oSheet.drawPage.getForms().getByIndex(0)
oDateField = oForm.getByName("DateField1")
oDateField.removePropertyChangeListener("Text",oListener)
oListener = Nothing 'To know later this handler has stopped'
end if
End Sub
Sub Event_disposing(oEvent)
End Sub
Sub Event_propertyChange(oEvent)
Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
Mri oEvent
End Sub
These methods are only for this listener. If you create other listeners they must include the methods required for the particular listener.
Edit:
It is not certain this is what you need to accomplish your task since you never stated just what you are attempting to do.