It might be possible to compare user defined types [edit: generically, one function for all] using the CoreReflection service, but I couldn't work it out.
Another alternative, instead of an array as a substitute for a user type, is to build a substitute by joining Pair structs together.
I'm not sure there's any advantage over an array though:
Code: Select all
sub TestStructEnum
struct1 = CreateStructEnum(array(0,1,thiscomponent,3,4,5,6,7,8))
struct2 = CreateStructEnum(array(0,1,thiscomponent,3,4,5,6,7,8))
struct3 = CreateStructEnum(array(0,1,thiscomponent,3,4,5,60,7,8))
msgbox compareStructs(struct1,struct2)
msgbox compareStructs(struct1,struct3)
const seconditemname = 2 'set const for accessing index by name
mri GetStructEnumValue(struct1,seconditemname)
end sub
Function CreateStructEnum(arr)
dim ub,i
ub = ubound(arr)
dim pairs(ub)
for i = 0 to ub
pairs(i) = new "com.sun.star.beans.Pair<any,any>" 'first any can be another data type
pairs(i).first = arr(i)
next
for i = ub -1 to 0 step -1
pairs(i).second = pairs(i+1)
next
CreateStructEnum = pairs(0)
end function
function GetStructEnumValue(struct,v) as any
on local error goto outofrange
dim n,i
if v = 0 then
GetStructEnumValue = struct.first
else
n = struct
for i = 0 to v-1
n = n.second
next
GetStructEnumValue =n.first
end if
outofrange:
end function
function compareStructs(struct1,struct2)
dim EnMap
EnMap = com.sun.star.container.EnumerableMap.create("string", "any")
EnMap.put("0", struct1)
compareStructs = EnMap.containsValue(struct2)
end function