I may not have been clear enough in my question but I wanted to access the properties of objects programatically. XRay and MRI are very useful tools but they don’t enable me to access the properties in my macro.
However, I found the solution in Andrew Pitonyak’s book: OpenOffice.org Macros Explained, Third Edition. Once we have the names of the properties of an object (e.g. using the property DBG_properties), we can access them in the following two ways:
-
If the object supports the com.sun.star.beans.XPropertySetInfo interface then we can retrieve the value of certain properties using the getPropertyValue(propertyName)
method. However, not all of the properties are available through this interface, so this method sometimes produces an error.
-
In all cases, we can insert a new module into a library, containing a function that returns the value of the desired property.
My function returning the value of a given property can be seen below. In order to run properly, you will need a library called “TestLib” and it also has to be loaded (double click on its name).
Function myGetPropertyValue (oObj As Object, sPropName As String) As Variant
Dim oPropInfo, oLib
Dim sCode As String
On Local Error GoTo NoProperty
oPropInfo = oObj.getPropertySetInfo()
If oPropInfo.hasPropertyByName (sPropName) Then
myGetPropertyValue = oObj.getPropertyValue (sPropName)
Exit Function
EndIf
NoProperty:
oLib = GlobalScope.BasicLibraries.getByName("TestLib")
sCode = "Option Explicit" & Chr$(10) & "Function getProp (oObj As Object)" & _
Chr$(10) & _ "On Local Error GoTo propErr" & Chr$(10) & _
"getProp = oObj." & sPropName & Chr$(10) & "Exit Function" & Chr$(10) & _
"propErr:" & Chr$(10) & "getProp = Error" & Chr$(10) & "End Function"
oLib.insertByName ("MyTest", sCode)
myGetPropertyValue = getProp (oObj)
oLib.removeByName("MyTest")
End Function