Ask Your Question

Function to return properties of an object rather than their names

asked 2016-02-05 02:00:15 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I know that UNO objects have the property DBG_properties, which returns a string with the names of the properties supported by that object. However, I want to access those properties, for which I would need the properties themselves, not only their names as strings.

Is it possible in Libreoffice Basic to get a list of the properties of an object rather than just their names?

For example, let's suppose that I have a UNO structure and I want to retrieve its properties (Name and Value) without knowing the names of the properties. And if the property happens to be an object then I want to access its properties, too, and so on.

Thank you in advance.

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted

answered 2016-02-05 22:39:42 +0200

karolus gravatar image


In this context we should also mention about Mri -which seems have some comparative advantages versus Xray ( non-blocking execution, kind of Code generation for Basic, Python, Java, ...; )

personally I "do" lot of Introspection interactive from ipython notebook sessions with the advantage of

someobject.<[tab]> ...  #produces complete method_tree of someobject

more Details about that stuff ... scroll down to my answer

edit flag offensive delete link more

answered 2016-02-05 17:36:05 +0200

pierre-yves samyn gravatar image


The future version 5.1 will add a new service allowing easy access to the documentation.

Meanwhile there are tools. I personally use XRay. Its purpose is to display the properties, methods, services, interfaces which are provided by an object variable. X-Ray is a tool, originally developed for by Bernard Marcelly.


edit flag offensive delete link more

answered 2016-02-19 10:41:44 +0200

Gabor2 gravatar image

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: 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 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
        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)
End Function
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-02-05 02:00:15 +0200

Seen: 959 times

Last updated: Feb 19 '16