Is there any way to determine the type of a UNO structure?
For example, if from macro code I obtain the rangeAddress of a range of cells and save it in a variable, the IDE informs me that the type of the variable content is “com.sun.star.table.RangeAddress”
But how can I test if a variable contains a structure of type “com.sun.star.table.RangeAddress” ?
Not being a UNO object it does not support supportsService
For now I can only do it using a function with on error goto to detect if the variable supports startColumn,etc properties)
Are there other systems?
Thanks in advance for any suggestion
Structs have »typeNames«
in python:
Thanks, but unfortunately I don’t use Python and Java.
This is a possible solution in StarBasic, an extended version of implementationName
Sub fImplementationName_Test()
oRange = ThisComponent.Sheets(0).getCellRangeByName("A1")
msgbox fImplementationName(oRange)
oAddr = oRange.CellAddress
msgbox fImplementationName(oAddr)
end sub
function fImplementationName(o)
dim s,sConfr,i0,i1
s=o.dbg_properties(o)
sConfr=""""
i0=instr(s,sConfr)
i1=instr(i0+1,s,sConfr)
fImplementationName=mid(s,i0+1,i1-i0-1)
End function
Or a little more compact:
' Returns the type of the Uno structure
Function fImplementationName(Byval o)
fImplementationName=Split(o.dbg_properties(), """")(1)
End Function
It’s true, very very compact
Hi,
you may query the .dbg_Properties
property of any UNO structure.
For example, in a Calc spreadsheet:
Sub Main
oRange = ThisComponent.Sheets(0).getCellRangeByName(“A1:A2”)
oAddr = oRange.RangeAddress
MsgBox oAddr.dbg_properties
End Sub
Returns:
Thank you very much! I never noticed that dbg_properties provides the type of the structure at the beginning, just extract it from the string produced.
This solves me many other similar problems, very thanks for the solution