Creating UNO Values for OOo Internals


OOo Basic does an excellent job of converting between the native Basic types and the types required internally by OOo. However, if you call a method on a Universal Network Object and OOo Basic doesn't know what the type should be, it may not properly convert the type. For example, the setProperty Value method in the XPropertySet interface accepts two arguments-a string name of the property to set and the value to set. The type of the value to set depends on which property is set. Use the function CreateUnoValue (shown in Listing 13 ) to create a reference to a Universal Network Object that contains the appropriate type if there is a problem creating the correct type. I have never seen this happen, so don't fret that much about your arguments; you can almost always trust OOo Basic to do the correct thing.

Listing 13: Use CreateUnoValue to create a reference to an internal UNO value.
start example
 Dim v v = CreateUnoValue("unsigned long", 10) v = CreateUnoValue("string", "hello") v = CreateUnoValue("byte", 10)                'A byte is from 0 through 255 v = CreateUnoValue("[]byte", Array(3, 2, 1))  'You can even create arrays 'v = CreateUnoValue("Byte", 10)               'No such element exception 'v = CreateUnoValue("byte", 1000)             'Out of range exception 'v = CreateUnoValue("uint64", 10)             'No such element exception 
end example
 

The first argument to CreateUnoValue is the data type that should be created. By reading the OOo source code, I know that the supported data types are void, char, boolean, byte, short, unsigned short, long, unsigned long, hyper, unsigned hyper, float, double, string, type, and any. The names are case sensitive and may be preceded by square brackets to indicate an array. The value returned by CreateUNOValue is not usable by OOo Basic; it is only useful to the internals of OOo. In other words, do not create a "byte" type and then expect to use it as a number.




OpenOffice.org Macros Explained
OpenOffice.org Macros Explained
ISBN: 1930919514
EAN: 2147483647
Year: 2004
Pages: 203

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net