Basic Macro UserDef Types, get Actual DataTypes and Names within defined UserType

Hello,

Hoping somebody can help me please!!!

I think I know the answer could well be no as I have been searching around and trying different things like Collections, Enum Maps etc but still haven’t found a solution apart from generating the physical script at runtime and placing it in a module.

Scenario…

I create a user def type ie

Type myType
oSomeObject As Object
sSomeFName As String
sSomeLName As String
nSomeNumber As Integer
End Type

Dim tType as New myType

now I know if I want to assign a value to say sSomeFName then I would do something like this…
tType.sSomeFName = “Pet”

And if I want the value of that var at a later stage I would do something like this
Dim sVar
sVar = tType.sSomeFName

and so on etc etc

but is it possible to access the actual datatypes and names in the userdef type ie something like
Dim t
Dim nCount
Dim oSomeType()
Dim oSomeTypeName()
nCount = tType.numOfDataTypes …cannot find any such function apart from UBound for Arrays which wont work.

ReDim oSomeType(nCount)
ReDim oSomeTypeName(nCount)

For Each t in tType
oSomeTypeName(nCount) = getDataTypeName(t) …so on 1st loop this would be ‘oSomeObject’ and on the 2nd this would be ‘sSomeFName’

oSomeType(nCount) = getDataType(t) … and again on the 1st loop this would be ‘Object’ and on the 2nd this would be ‘String’ …and so on
Next t

I can get the Type from say “tType” via TypeName and VarType etc but that only brings up the initial type as an object not the parts that make it up.

I know it will be said, “well if you are using a user def type you should know what it is made up of” :smiley: , which is right and true but I have found myself wanting to get the physical make up of some types like the above without having to back track in coding all the time.

Is this possible or is there perhaps another way to achieve this?? :thinking:

Many thanks
P.R

Latest Basic Voodoo on forum.openoffice.org

Hi Villeroy,

Thanks for the quick reply and the link.

I will look into these examples and report back. :smiley:

Many thanks
P.R

Hi Villeroy,

I looked at the examples but nothing seems to want to work with user def types, single things are ok but anything like an array or union type or similar are just ignored and looked at as an single object and not the parts.

I am not sure but I think something in Corereflection is causing this action looking at it.

I can copy an existing struct like in the examples ie ccc.awt.size or point but I suspect there is a lookup somewhere deep in the coding that perhaps looks at something like the idl files to check it exists but cannot be sure but certainly user def types get thrown out as well.

Unless I am missing something (which wouldn’t surprise me :laughing:), I suspect the way forward and a cop-out, is to generate the code at runtime, place it in a module and manipulate it that way as to generate a user def type at runtime I would also need to know the details of it.

I also looked at maps etc but they only seem to be for pairs etc , not say a 5 line usertype with different datatypes.

Is it me or is this a limitation of Core reflection only able to deal with single datatypes?

Many thanks
P.R

You can write macros in Python, JavaScript, Java.

You can write macros in Python, JavaScript, Java.

Yes, but I was hoping keep all in-house so to speak…

Ok, well thanks anyhow. :smile:

P.R

Hi Villeroy,

Following on from my last comment, I have tried with Python(not my strong suit) to unravel a passed Type from LO Basic via using getScriptProvider->getScript and invoke.

It works (again) with single datatype ie string etc, but when it comes to sending over a LO UserType then seems to be a problem with Python (afaics) splitting up such a type so it can be read.

The strange thing is that if a def func receives the type as an argument and returning straight back without any processing inbetween (Experiment to see what was going on) LO receives the type back in its original format but still the same problem remains, as trying to get the inner datatypes etc.

I have searched on the net but cannot find anything that would point in how to read the sent type into list/arrays etc in Python.

Do you know how Python would split up such a Type?

Many thanks :smile:
P.R