Scriptom provides a simple yet powerful COM library for Groovy. It is implemented as a thin layer around JACOB (Java COM Bridge). JACOB is a mature open-source library for Java that supports communicating with COM libraries and automation servers on Microsoft Windows.
Scriptom attempts to mirror all the functionality of JACOB, but in a "groovy" way.
Here is a quick example that uses Scripting.FileSystemObject
to list the paths
to all active rooted drives on your system (italics show COM methods and properties):
new ActiveXObject('Scripting.FileSystemObject').Drives.findAll{it.IsReady}.each{println it.Path}
Visual Basic was never this easy!
Variant-Type | Supported? | Java | VB6/VBA | Comments |
---|---|---|---|---|
Empty | Yes | null | Variant.Empty | - |
Null | Yes | VariantNull | Variant.Null | Don't be confused. Variant.Null is not the same as null . This is
by design. |
Short | Yes | Short | Integer | An Integer in VB6 represents a 16-bit signed value. |
Int | Yes | Integer | Long | A Long in VB6 represents a 32-bit signed value. |
Long | Yes | Long/BigInteger | - | A 64-bit signed value. Supported by .NET. BigInteger supports arbitrary-precision integers, so there may be errors associated with converting a BigInteger to a 64-bit integer. |
Float | Yes | Float | Single | - |
Double | Yes | Double | Double | Note that BigDecimal s are converted to Double s. |
Currency | Yes | BigDecimal | Variant.Currency | Currency is mapped to Variant.Decimal by Scriptom, overriding the default behavior in Jacob. Currency has less precision than Decimal, so there may be errors in the conversion. |
Decimal | yes | BigDecimal | - | Decimal is supported by .NET. For VB6, the COM layer will convert a Decimal to the equivalent type automatically. BigDecimal can contain numbers larger than Decimal, so there are issues converting very large numbers. |
Date | Yes | Date | Date | - |
String | Yes | String | String | - |
Dispatch | Yes | COM Object | ActiveXObject | - |
Error | Partial | VariantError | MISSING parameter, ??? | JACOB partially supports this type as of version 1.12. Scriptom can consume VariantError instances, but can only create the value corresponding to MISSING (0x8002004). If you attempt to pass a VariantError other than MISSING as an argument, it is passed as an integer. |
Boolean | Yes | Boolean | Boolean | - |
Variant | Yes | Java POJO | Variant | Scriptom supports type Variant when combined with Array, which is an array that can hold any variant type. |
Object (Unknown) | No | - | - | Unknown how this is used. JACOB does not appear to support it. |
Byte | Yes | Byte | Byte | - |
TypeMask | No | - | - | Unknown what this is used for. Does not appear to be supported by JACOB. |
Array | Yes | SafeArrayProxy | Variant | JACOB supports Variant Array conversion to and from SafeArrays. SafeArrays support a
subset of the Variant types, and byref passing is not currently working.
The Scriptom SafeArrayProxy fully supports typed, n-dimensional
SafeArrays. |
By default, all Variants in Scriptom are passed by value (not 'byref'). Note that it is
safe to pass values 'byval' even when the method argument is marked as 'byref.'
In COM, 'byref' arguments allow a method to change a value which is then reflected
in the calling scope. If you need to do this, take a look at the VariantByref
class. You shouldn't run into this very often with the standard COM libraries, but isn't
it nice to know we've got your back?
Unsigned integer types are also supported by Scriptom. Each COM unsigned type is converted to equivalent signed Java type.