VariantClear
f90VB Modules
f90VBDefs, f90VBVariants
Summary
Clears the contents of a variant and sets the variant to VT_EMPTY.
Syntax
| subroutine VariantClear | (VarDest, iRet) |
| type(VARIANT),intent(inout):: | VarDest |
| integer(HRESULT_KIND),intent(out),optional:: | iRet |
Arguments
VarDest [Input/Output]
Variant to be cleared. It must be an initialized variant.
iRet [Output/Optional]
Upon return, iRet contains S_OK or an error code. See comments for more information.
Comments
VariantClear is used to clear the contents of initialized variants. Use VariantClear before a variant variable goes out of scope (i.e. to release the contents of local variants before leaving a subroutine or function).
VariantClear sets the content of VarDest to VT_EMPTY. In addition, if VarDest had a reference to a BString or Safe Array, VariantClear calls StrFree to release the memory use by the BString or SafeArrayDestroy to destroy the contained Safe Array. If VarDest had a reference to an object, VariantClear calls the object’s Release method.
You don’t need to call VariantClear for variants that contain values that are not dynamically allocated. For example, you don’t need to call this subroutine to clear a variant containing a VT_I4 (an integer) or a VT_R4 (real) value. Note, however, that failure to call VariantClear on variants that contain dynamically allocated values may result in memory leaks, because the BString or Safe Array referenced by the variant may never be released.
Argument iRet
Indicates success or failure of the subroutine. The following codes can be returned in this argument:
| Value returned in argument iRet | Description | |
| S_OK | Success. | |
| DISP_E_BADVARTYPE | The variant VarDest has an invalid vtType. This usually happens when the variant has not been initialized. | |
| DISP_E_ARRAYISLOCKED | The destination variant contains an array that is locked | |
| E_INVALIDARG | One of the arguments is invalid. | |
Examples
See examples for VariantCreate and VariantCopy.
Related Topics
| For information about: | See: | |
| Initializing variants | VariantInit | |
| Creating new variants | VariantCreate | |
| Copying a Variant | VariantCopy | |