Help Center

DVARIANT.Constructorsconstructor

Initialize the class with the specified value.

COMconstructorDVARIANT.INCdoc-orphan
No implementation located. This member is documented, but the source scan found no matching declaration. It is likely declared in a header this scan does not resolve, or provided by a macro.

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

NameDescription
cvA DVARIANT.
vA VARIANT.
pvarPointer to a VARIANT.
cyA currency structure.
decA decimal structure.
bA boolean value (TRUE or FALSE).
pwszPointer to an unicode string. You can also pass a Free Basic ansi string or a string literal.
bsA BSTRING.
dwsA DWSTRING.
pDispPointer to a DISPATCH interface.
pUnkPointer to a UNKNOWN interface.
_valueA numeric value or variable.
_pvarPointer to a variable. This will create a VT_BYREF variant of the specified type.
_vtypeThe variant type, e.g. VT_I4, VT_UI4.
strTypeThe variant type as a string: "BOOL", "BYTE", "UBYTE", "SHORT", "USHORT, "INT", UINT", "LONG", "ULONG", "LONGINT", "SINGLE, "DOUBLE", "NULL".
fAddRefTRUE 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