Package com.ms.com |
![]() Previous |
![]() Contents |
![]() Index |
![]() Next |
public final class Variant { // Fields public static final short VariantEmpty = 0; public static final short VariantNull = 1; public static final short VariantShort = 2; public static final short VariantInt = 3; public static final short VariantFloat = 4; public static final short VariantDouble = 5; public static final short VariantCurrency = 6; public static final short VariantDate = 7; public static final short VariantString = 8; public static final short VariantDispatch = 9; public static final short VariantError = 10; public static final short VariantBoolean = 11; public static final short VariantVariant = 12; public static final short VariantObject = 13; public static final short VariantByte = 17; public static final short VariantTypeMask = 0xfff; public static final short VariantArray = 0x2000; public static final short VariantByref = 0x4000; // Constructors public Variant(); public Variant(int val); public Variant(double val); public Variant(boolean val); public Variant(String val); public Variant(SafeArray val, boolean fByRef); public Variant(Object value); public Variant(int vartype, int val); public Variant(int vartype, boolean val); public Variant(int vartype, double val); public Variant(int vartype, Object val); // Methods public void getEmpty (); public void getNull (); public short getShort (); public int getInt (); public float getFloat (); public double getDouble (); public long getCurrency (); public double getDate (); public native String getString (); public native Object getDispatch (); public int getError (); public native boolean getBoolean (); public native Object getObject (); public byte getByte (); public void putEmpty ( ); public void putNull ( ); public void putShort (short val); public void putInt (int val); public void putFloat (float val); public void putDouble (double val); public void putCurrency (long val); public void putDate (double val); public native void putString (String val); public native void putDispatch (Object val); public void putError (int val); public void putBoolean (boolean val); public native void putObject (Object val); public void putByte (byte val); public native void putShortRef (short val); public native void putIntRef (int val); public native void putFloatRef (float val); public native void putDoubleRef(double val); public native void putCurrencyRef(long val); public native void putDateRef (double val); public native void putStringRef(String val); public native void putDispatchRef(Object val); public native void putErrorRef (int val); public native void putBooleanRef(boolean val); public native void putObjectRef(Object val); public native void putByteRef (byte val); public native short getShortRef (); public native int getIntRef (); public native float getFloatRef (); public native double getDoubleRef (); public native long getCurrencyRef(); public native double getDateRef (); public native String getStringRef (); public native Object getDispatchRef(); public native int getErrorRef (); public native boolean getBooleanRef (); public native Object getObjectRef (); public native byte getByteRef (); public native short toShort () throws ClassCastException; public native int toInt () throws ClassCastException; public native float toFloat () throws ClassCastException; public native double toDouble () throws ClassCastException; public native long toCurrency () throws ClassCastException; public native double toDate () throws ClassCastException; public native String toString (); public native Object toDispatch () throws ClassCastException; public native int toError () throws ClassCastException; public native boolean toBoolean () throws ClassCastException; public native Object toObject () throws ClassCastException; public native byte toByte () throws ClassCastException; public SafeArray toSafeArray() throws ClassCastException; public void noParam (); public native void putVariantArray(Variant v[]); public native void putVariantArrayRef(Variant v[]); public native Variant[] getVariantArray(); public native Variant[] getVariantArrayRef(); public native Variant[] toVariantArray(); public native void putByteArray(Object ba); public native void putCharArray(Object ca); public native Object toByteArray(); public native Object toCharArray(); }
The Variant class is used to bridge Java with ActiveX components that manipulate VARIANT data types.
Most Variant methods fall into one of three categories:
toXXX() methods which attempts to coerce the Variant to type XXX and return the converted value. The results of the coercion are not copied back to the Variant. Coersion is performed using the Win32 VariantChangeType() api. If the Variant cannot be converted to the requested type, a ClassCastException is thrown.
getXXX() methods which succeed only if the Variant is already the correct type. If not, ClassCastException is thrown.
putXXX(y) methods which changes the vartype of a Variant and initializes it to a new value. In general, it is better to construct and initialize the Variant atomically using an overloaded constructor rather using one of these methods.
public Variant()Creates a Variant of type VT_EMPTY.
public Variant(int val)Creates a Variant of type VT_I4.
Parameter Description val the initial value of the Variant.
public Variant(double val)Creates a Variant of type VT_R8.
Parameter Description val the initial value of the Variant.
public Variant(boolean val)Creates a Variant of type VT_BOOL.
Parameter Description val the initial value of the Variant.
public Variant(String val)Creates a Variant of type VT_BSTR.
Parameter Description val the initial value of the Variant.
public Variant(SafeArray val, boolean fByRef)Creates a Variant of type VT_ARRAY or VT_BYREF|VT_ARRAY.
Typically, fByRef is true when creating a Variant to pass as a parameter, and false when creating a Variant to be used as a return value.
If fByRef is true, any changes made to the SAFEARRAY through the new Variant will be visible to the SafeArray instance used to initialize the Variant.
If fByRef is false, the method revokes the SafeArray instance's ownership and any further operations on that instance will throw an exception. This is because ownership of the SAFEARRAY has been transferred to the new Variant. To retrieve any changes made through the Variant, you must call Variant.toSafeArray() to obtain a new proxy.
Parameter Description val the initial SafeArray value fByRef whether to set VT_BYREF modifier.
public Variant(Object value)Creates a Variant of type VT_DISPATCH or VT_BYREF|VT_ARRAY.
If the argument is of type com.ms.com.SafeArray, this constructor is equivalent to:
Variant(val, true)
Otherwise, this constructor creates a VT_DISPATCH.
Parameter Description val the initial value
public Variant(int vartype, int val)Creates a Variant of the indicated vartype. The vartype can be VariantShort, VariantInt, or VariantByte. The VariantByref modifier can be set on any of these.
Parameter Description vartype the vartype. val the initial value
public Variant(int vartype, boolean val)Creates a Variant of the indicated vartype. The vartype can be VariantBoolean, or VariantByref|VariantBoolean.
Parameter Description vartype the vartype val the initial value
public Variant(int vartype, double val)Creates a Variant of the indicated vartype. The vartype can be VariantDouble, VariantFloat, or VariantDate. The VariantByref modifier can be set on any of these.
Parameter Description vartype the vartype. val the initial value
public Variant(int vartype, Object val)Creates a Variant of the indicated vartype. The vartype can be VariantString, VariantObject, or VariantDispatch. The VariantByref modifier can be set on any of these.
Parameter Description vartype the vartype. val the initial value
public native boolean getBoolean ()Returns the value of a VT_BOOL variant. If the type is not VT_BOOL, a ClassCastException is thrown.
Return Value:
Returns the Variant's value converted to Java
public native boolean getBooleanRef ()Returns the referenced value of a VT_BYREF|VT_BOOL variant. If the Variant is of any other vartype, a ClassCastException is thrown.
Return Value:
Returns the Variant's referenced value converted to Java
public byte getByte ()Returns the value of a VT_UI1 variant. If the type is not VT_UI1, a ClassCastException is thrown.
Return Value:
Returns the Variant's value converted to Java
public native byte getByteRef ()Returns the referenced value of a VT_BYREF|VT_UI1 variant. If the Variant is of any other vartype, a ClassCastException is thrown.
Return Value:
Returns the Variant's referenced value converted to Java
public long getCurrency ()Returns the value of a VT_CY variant. If the type is not VT_CY, a ClassCastException is thrown.
Return Value:
Returns the Variant's value converted to Java
public native long getCurrencyRef()Returns the referenced value of a VT_BYREF|VT_CY variant. If the Variant is of any other vartype, a ClassCastException is thrown.
Return Value:
Returns the Variant's referenced value converted to Java
public double getDate ()Returns the value of a VT_DATE variant. If the type is not VT_DATE, a ClassCastException is thrown.
Return Value:
Returns the Variant's value converted to Java
public native double getDateRef ()Returns the referenced value of a VT_BYREF|VT_DATE variant. If the Variant is of any other vartype, a ClassCastException is thrown.
Return Value:
Returns the Variant's referenced value converted to Java
public native Object getDispatch ()Returns the value of a VT_DISPATCH variant. If the type is not VT_DISPATCH, a ClassCastException is thrown.
Return Value:
Returns the Variant's value converted to Java
public native Object getDispatchRef()Returns the referenced value of a VT_BYREF|VT_DISPATCH variant. If the Variant is of any other vartype, a ClassCastException is thrown.
Return Value:
Returns the Variant's referenced value converted to Java
public double getDouble ()Returns the value of a VT_R8 variant. If the type is not VT_R8, a ClassCastException is thrown.
Return Value:
Returns the Variant's value converted to Java
public native double getDoubleRef ()Returns the referenced value of a VT_BYREF|VT_R8 variant. If the Variant is of any other vartype, a ClassCastException is thrown.
Return Value:
Returns the Variant's referenced value converted to Java
public void getEmpty ()Verifies that the vartype is VT_EMPTY, otherwise throws a ClassCastException. That is all this method does since there is no value associated with an empty variant.
public int getError ()Returns the value of a VT_ERROR variant. If the type is not VT_ERROR, a ClassCastException is thrown.
Return Value:
Returns the Variant's value converted to Java
public native int getErrorRef ()Returns the referenced value of a VT_BYREF|VT_ERROR variant. If the Variant is of any other vartype, a ClassCastException is thrown.
Return Value:
Returns the Variant's referenced value converted to Java
public float getFloat ()Returns the value of a VT_R4 variant. If the type is not VT_R4, a ClassCastException is thrown.
Return Value:
Returns the Variant's value converted to Java
public native float getFloatRef ()Returns the referenced value of a VT_BYREF|VT_R4 variant. If the Variant is of any other vartype, a ClassCastException is thrown.
Return Value:
Returns the Variant's referenced value converted to Java
public int getInt ()Returns the value of a VT_I4 variant. If the type is not VT_I4, a ClassCastException is thrown.
Return Value:
Returns the Variant's value converted to Java
public native int getIntRef ()Returns the referenced value of a VT_BYREF|VT_I4 variant. If the Variant is of any other vartype, a ClassCastException is thrown.
Return Value:
Returns the Variant's referenced value converted to Java
public void getNull ()Verifies that the vartype is VT_NULL, otherwise throws a ClassCastException. That is all this method does since there is no value associated with a null variant.
public native Object getObject ()Returns the value of a VT_UNKNOWN variant. If the type is not VT_UNKNOWN, a ClassCastException is thrown.
Return Value:
Returns the Variant's value converted to Java
public native Object getObjectRef ()Returns the referenced value of a VT_BYREF|VT_UNKNOWN variant. If the Variant is of any other vartype, a ClassCastException is thrown.
Return Value:
Returns the Variant's referenced value converted to Java
public short getShort ()Returns the value of a VT_I2 variant. If the type is not VT_I2, a ClassCastException is thrown.
Return Value:
Returns the Variant's value converted to Java
public native short getShortRef ()Returns the referenced value of a VT_BYREF|VT_I2 variant. If the Variant is of any other vartype, a ClassCastException is thrown.
Return Value:
Returns the Variant's referenced value converted to Java
public native String getString ()Returns the value of a VT_BSTR variant. If the type is not VT_BSTR, a ClassCastException is thrown.
Return Value:
Returns the Variant's value converted to Java
public native String getStringRef ()Returns the referenced value of a VT_BYREF|VT_BSTR variant. If the Variant is of any other vartype, a ClassCastException is thrown.
Return Value:
Returns the Variant's referenced value converted to Java
public native Variant[] getVariantArray()Returns the value of a VT_ARRAY|VT_VARIANT variant. The embedded array must be one-dimensional. This is an expensive method and has been superceded by the toSafeArray method.
Return Value:
Returns the Variant's value converted to Java
public native Variant[] getVariantArrayRef()Returns the referenced value of a VT_BYREF|VT_ARRAY|VT_VARIANT variant. The embedded array must be one-dimensional. This is an expensive method and has been superceded by the toSafeArray method.
Return Value:
Returns the Variant's referenced value converted to Java
public void noParam ()Sets a Variant to represent a missing optional parameter. This method is equivalent to:
putError(0x80020004) //DISP_E_PARAMNOTFOUND
public void putBoolean (boolean val)Sets Variant to be type VT_BOOL and clears the previous contents. The preferred way to create a VT_BOOL Variant is the expression:
new Variant(val)
Parameter Description val new value
public native void putBooleanRef(boolean val)Replaces a value referenced by a VT_BYREF|VT_BOOL Variant. This method can also be used to initialize a Variant, but the preferred method is the expression:
new Variant(Variant.VariantByref|Variant.VariantBoolean, val)
Parameter Description val new value
public void putByte (byte val)Sets Variant to be type VT_UI1 and clears the previous contents. The preferred way to create a VT_UI1 Variant is the expression:
new Variant(Variant.VariantByte, val)
Parameter Description val new value
public native void putByteArray(Object ba)Sets Variant to be type VT_ARRAY|VT_UI1 and clears the previous contents.
Parameter Description ba initial values of elements: must be of type byte[]
public native void putByteRef (byte val)Replaces a value referenced by a VT_BYREF|VT_UI1 Variant. This method can also be used to initialize a Variant, but the preferred method is the expression:
new Variant(Variant.VariantByref|Variant.VariantByte, val)
Parameter Description val new value
public native void putCharArray(Object ca)Sets Variant to be type VT_ARRAY|VT_I2 and clears the previous contents.
Parameter Description ba initial values of elements: must be of type char[]
public void putCurrency (long val)Sets Variant to be type VT_CY and clears the previous contents.
Parameter Description val new value
public native void putCurrencyRef(long val)Replaces a value referenced by a VT_BYREF|VT_CY Variant.
Parameter Description val new value
public void putDate (double val)Sets Variant to be type VT_DATE and clears the previous contents. The preferred way to create a VT_DATE Variant is the expression:
new Variant(Variant.VariantDate, val)
Parameter Description val new value
public native void putDateRef (double val)Replaces a value referenced by a VT_BYREF|VT_DATE Variant. This method can also be used to initialize a Variant, but the preferred method is the expression:
new Variant(Variant.VariantByref|Variant.VariantDate, val)
Parameter Description val new value
public native void putDispatch (Object val)Sets Variant to be type VT_DISPATCH and clears the previous contents. The preferred way to create a VT_DISPATCH Variant is the expression:
new Variant(val)
Parameter Description val new value
public native void putDispatchRef(Object val)Replaces a value referenced by a VT_BYREF|VT_DISPATCH Variant. This method can also be used to initialize a Variant, but the preferred method is the expression:
new Variant(Variant.VariantByref|Variant.VariantDispatch, val)
Parameter Description val new value
public void putDouble (double val)Sets Variant to be type VT_R8 and clears the previous contents. The preferred way to create a VT_R8 Variant is the expression:
new Variant(val)
Parameter Description val new value
public native void putDoubleRef(double val)Replaces a value referenced by a VT_BYREF|VT_R8 Variant. This method can also be used to initialize a Variant, but the preferred method is the expression:
new Variant(Variant.VariantByref|Variant.VariantDouble, val)
Parameter Description val new value
public void putEmpty ( )Sets Variant to be type VT_EMPTY and clears the previous contents. The expression:
new Variant()
creates a new Variant that is already type VT_EMPTY so it is not necessary to invoke putEmpty() on it.
public void putError (int val)Sets Variant to be type VT_ERROR and clears the previous contents. This is normally passed as placeholder for a missing optional parameter. The preferred way to generate a missing parameter is:
Variant v = new Variant(val);
v.noParam();
Parameter Description val new value
public native void putErrorRef (int val)Replaces a value referenced by a VT_BYREF|VT_ERROR Variant.
Parameter Description val new value
public void putFloat (float val)Sets Variant to be type VT_R4 and clears the previous contents. The preferred way to create a VT_R4 Variant is the expression:
new Variant(Variant.VariantFloat, val)
Parameter Description val new value
public native void putFloatRef (float val)Replaces a value referenced by a VT_BYREF|VT_R4 Variant. This method can also be used to initialize a Variant, but the preferred method is the expression:
new Variant(Variant.VariantByref|Variant.VariantFloat, val)
Parameter Description val new value
public void putInt (int val)Sets Variant to be type VT_I4 and clears the previous contents. The preferred way to create a VT_I4 Variant is the expression:
new Variant(val)
Parameter Description val new value
public native void putIntRef (int val)Replaces a value referenced by a VT_BYREF|VT_I4 Variant. This method can also be used to initialize a Variant, but the preferred method is the expression:
new Variant(Variant.VariantByref|Variant.VariantInt, val)
Parameter Description val new value
public void putNull ( )Sets Variant to be type VT_NULL and clears the previous contents.
public native void putObject (Object val)Sets Variant to be type VT_UNKNOWN and clears the previous contents. The preferred way to create a VT_UNKNOWN Variant is the expression:
new Variant(Variant.VariantObject, val)
Parameter Description val new value
public native void putObjectRef(Object val)Replaces a value referenced by a VT_BYREF|VT_UNKNOWN Variant. This method can also be used to initialize a Variant, but the preferred method is the expression:
new Variant(Variant.VariantByref|Variant.VariantObject, val)
Parameter Description val new value
public void putShort (short val)Sets Variant to be type VT_I2 and clears the previous contents. The preferred way to create a VT_I2 Variant is the expression:
new Variant(Variant.VariantShort, val)
Parameter Description val new value
public native void putShortRef (short val)Replaces a value referenced by a VT_BYREF|VT_I2 Variant. This method can also be used to initialize a Variant, but the preferred method is the expression:
new Variant(Variant.VariantByref|Variant.VariantShort, val)
Parameter Description val new value
public native void putString (String val)Sets Variant to be type VT_BSTR and clears the previous contents. The preferred way to create a VT_BSTR Variant is the expression:
new Variant(val)
Parameter Description val new value
public native void putStringRef(String val)Replaces a value referenced by a VT_BYREF|VT_BSTR Variant. This method can also be used to initialize a Variant, but the preferred method is the expression:
new Variant(Variant.VariantByref|Variant.VariantString, val)
Parameter Description val new value
public native void putVariantArray(Variant v[])Sets Variant to be type VT_ARRAY|VT_VARIANT that holds a zero-based one-dimensional SafeArray.
Parameter Description v provides initial values for the SAFEARRAY elements.
public native void putVariantArrayRef(Variant v[])Replaces a SAFEARRAY referenced by a VT_BYREF|VT_ARRAY|VT_VARIANT Variant. This method can also be used to initialize a Variant, but the preferred method is to pass a SafeArray object to the Variant() constructor.
Parameter Description v provides initial values for the SAFEARRAY elements.
public native boolean toBoolean () throws ClassCastExceptionCoerces the Variant to a VT_BOOL, and returns the coerced result. The results of the coersion are not stored back in the Variant. If the Variant's type cannot be coerced, a ClassCastException is thrown.
Return Value:
Returns the coerced value converted to Java
public native byte toByte () throws ClassCastExceptionCoerces the Variant to a VT_UI1, and returns the coerced result. The results of the coersion are not stored back in the Variant. If the Variant's type cannot be coerced, a ClassCastException is thrown.
Return Value:
Returns the coerced value converted to Java
public native Object toByteArray()Returns the value of a VT_ARRAY|VT_UI1 or VT_BYREF|VT_ARRAY|VT_UI1, as a one-dimensional byte[] array. This method has been superceded by the toSafeArray() method.
Return Value:
Returns a byte array
public native Object toCharArray()Returns the value of a VT_ARRAY|VT_I2 or VT_BYREF|VT_ARRAY|VT_I2, as a one-dimensional char[] array. This method has been superceded by the toSafeArray() method.
Return Value:
Returns a char array
public native long toCurrency () throws ClassCastExceptionCoerces the Variant to a VT_CY, and returns the coerced result. The results of the coersion are not stored back in the Variant. If the Variant's type cannot be coerced, a ClassCastException is thrown.
Return Value:
Returns the coerced value converted to Java
public native double toDate () throws ClassCastExceptionCoerces the Variant to a VT_DATE, and returns the coerced result. The results of the coersion are not stored back in the Variant. If the Variant's type cannot be coerced, a ClassCastException is thrown.
Return Value:
Returns the coerced value converted to Java
public native Object toDispatch () throws ClassCastExceptionCoerces the Variant to a VT_DISPATCH, and returns the coerced result. The results of the coersion are not stored back in the Variant. If the Variant's type cannot be coerced, a ClassCastException is thrown.
Return Value:
Returns the coerced value converted to Java
public native double toDouble () throws ClassCastExceptionCoerces the Variant to a VT_R8, and returns the coerced result. The results of the coersion are not stored back in the Variant. If the Variant's type cannot be coerced, a ClassCastException is thrown.
Return Value:
Returns the coerced value converted to Java
public native int toError () throws ClassCastExceptionCoerces the Variant to a VT_ERROR, and returns the coerced result. The results of the coersion are not stored back in the Variant. If the Variant's type cannot be coerced, a ClassCastException is thrown.
Return Value:
Returns the coerced value converted to Java
public native float toFloat () throws ClassCastExceptionCoerces the Variant to a VT_R4, and returns the coerced result. The results of the coersion are not stored back in the Variant. If the Variant's type cannot be coerced, a ClassCastException is thrown.
Return Value:
Returns the coerced value converted to Java
public native int toInt () throws ClassCastExceptionCoerces the Variant to a VT_I4, and returns the coerced result. The results of the coersion are not stored back in the Variant. If the Variant's type cannot be coerced, a ClassCastException is thrown.
Return Value:
Returns the coerced value converted to Java
public native Object toObject () throws ClassCastExceptionCoerces the Variant to a VT_UNKNOWN, and returns the coerced result. The results of the coersion are not stored back in the Variant. If the Variant's type cannot be coerced, a ClassCastException is thrown.
Return Value:
Returns the coerced value converted to Java
public SafeArray toSafeArray() throws ClassCastExceptionExtracts a SafeArray from a Variant that has the VT_ARRAY modifier set. This operation does not create an independent SafeArray; thus, it can be used to modify the elements of the SafeArray referenced by the Variant.
Return Value:
Returns the coerced value converted to Java
public native short toShort () throws ClassCastExceptionCoerces the Variant to a VT_I2, and returns the coerced result. The results of the coersion are not stored back in the Variant. If the Variant's type cannot be coerced, a ClassCastException is thrown.
Return Value:
Returns the coerced value converted to Java
public native String toString ()Coerces the Variant to a VT_BSTR, and returns the coerced result. The results of the coersion are not stored back in the Variant. If the Variant's type cannot be coerced, a ClassCastException is thrown.
Return Value:
Returns the coerced value converted to Java
public native Variant[] toVariantArray()Returns the value of either a VT_ARRAY|VT_VARIANT or VT_BYREF|VT_ARRAY|VT_VARIANT variant. The embedded array must be one-dimensional. This is an expensive method and has been superceded by the toSafeArray method.
Return Value:
Returns the coerced value converted to Java
© 1997 Microsoft Corporation. All rights reserved. Legal Notices.