DVARIANT.Constructorsconstructor
Initialize the class with the specified value.
Syntax
CONSTRUCTOR
CONSTRUCTOR (BYREF dv AS DVARIANT)
CONSTRUCTOR (BYVAL v AS VARIANT)
CONSTRUCTOR (BYVAL pwsz AS WSTRING PTR)
CONSTRUCTOR (BYREF dws AS DWSTRING)
CONSTRUCTOR (BYREF bs AS BSTRING)
CONSTRUCTOR (BYVAL pvar AS VARIANT PTR)
CONSTRUCTOR (BYVAL cy AS CURRENCY)
CONSTRUCTOR (BYVAL dec AS DECIMAL)
DECLARE CONSTRUCTOR (BYVAL _value AS LONG)
CONSTRUCTOR (BYREF pDisp AS IDispatch PTR, BYVAL fAddRef AS BOOLEAN = FALSE)
CONSTRUCTOR (BYREF pUnk AS IUnknown PTR, BYVAL fAddRef AS BOOLEAN = FALSE)
CONSTRUCTOR (BYVAL _value AS LONGINT, BYVAL _vType AS WORD = VT_I4)
CONSTRUCTOR (BYVAL _value AS DOUBLE, BYVAL _vType AS WORD = VT_R8)
CONSTRUCTOR (BYVAL _value AS LONGINT, BYREF strType AS STRING)
CONSTRUCTOR (BYVAL _value AS DOUBLE, BYREF strType AS STRING)
CONSTRUCTOR (BYVAL _pvar AS ANY PTR, BYVAL _vType AS WORD)
CONSTRUCTOR (BYVAL _pvar AS ANY PTR, BYREF strType AS STRING)
Parameters
| Name | Description | |
|---|---|---|
cv | A DVARIANT. | |
v | A VARIANT. | |
pvar | Pointer to a VARIANT. | |
cy | A currency structure. | |
dec | A decimal structure. | |
b | A boolean value (TRUE or FALSE). | |
pwsz | Pointer to an unicode string. You can also pass a Free Basic ansi string or a string literal. | |
bs | A BSTRING. | |
dws | A DWSTRING. | |
pDisp | Pointer to a DISPATCH interface. | |
pUnk | Pointer to a UNKNOWN interface. | |
_value | A numeric value or variable. | |
_pvar | Pointer to a variable. This will create a VT_BYREF variant of the specified type. | |
_vtype | The variant type, e.g. VT_I4, VT_UI4. | |
strType | The variant type as a string: "BOOL", "BYTE", "UBYTE", "SHORT", "USHORT, "INT", UINT", "LONG", "ULONG", "LONGINT", "SINGLE, "DOUBLE", "NULL". | |
fAddRef | TRUE or FALSE. If TRUE, increases the reference count of the passed interface. |
Description
Creates an instance of the DVARIANT class.
Examples
DIM dv AS DVARIANT = "Test string" ' Creates a VT_BSTR (8) variant DIM dv AS DVARIANT = 12345 ' Creates a VT_I4 (3) variant DIM dv AS DVARIANT = 123456.78 ' Creates a VT_R8 (5) variant
SUB Foo (BYREF dv AS DVARIANT) PRINT dv END SUB
Foo "Test string" Foo 12345 Foo DVARIANT(12345, "LONG")
SUB Foo (BYVAL dv AS DVARIANT PTR) PRINT AfxDVarToStr(dv) END SUB Foo @DVARIANT("Test string") Foo @DVARIANT(12345) Foo @DVARIANT(12345, "LONG")`
SUB Foo (BYVAL v AS VARIANT) PRINT AfxVarToStr(v) END SUB
Foo DVARIANT("Test string") Foo DVARIANT(12345) Foo DVARIANT(12345, "LONG")
SUB Foo (BYVAL v AS VARIANT PTR) PRINT AfxVarToStr(v) END SUB Foo DVARIANT("Test string") Foo DVARIANT(12345) Foo DVARIANT(12345, "LONG")
We can use the constructors to pass values to parameters in procedures without assigning them first to a variable, e.g.:
Reference
- Include file
DVARIANT.INC - Documented in COM/DVARIANT Class.md
- Topic: DVARIANT Class