My Technical Notes

Tuesday, 10 February 2015

OpenOffice: Getting Type Name of an Object

XRay's source code is a treasure trove where it comes to "Reflection" code. Below is copied from XRayTool's source code:

Dim OOoReflection As Object
OOoReflection = CreateUnoService("")
classeIDL = OOoReflection.getType(obj)
MsgBox classeIDL.Name

Wherein `obj` is the object we wish to know the type name of.

The following function `GetTypeName` accepts an object `obj` as an argument and returns the type name:

Function GetTypeName(obj) As String
    Static coreReflection As Object

    If coreReflection Is Nothing Then
        coreReflection = CreateUnoService("")
    Dim classIDL
    classIDL = coreReflection.GetType(obj)
    GetTypeName = classIDL.Name
End Function

No comments: