De-referencing chained Variants
As you can see in Table 3.1, a Variant can contain a pointer to another Variant. The VT-Type of the first Variant would be the result of
ior(VT_BYREF,VT_VARIANT)
Now, there is nothing that prohibits the second Variant from also containing a pointer. You may be thinking that whoever calls your subroutine with such levels of indirection must have forgotten to take his daily prescription of Promazine, but the truth is that two or three levels of indirection are not uncommon in OLE/COM programming. Rather than attempting to institutionalize the culprits of this indirection madness, you can use subroutine VariantCopyInd, which will recursively unfold chained Variants to a basic VT-Type. Here is a simple example that illustrates how VariantCopyInd works.
Example 3.1
program Example31
use f90VBDefs
use f90VBVariants
implicit none
type(VARIANT)::vVar1, vVar2,vVarDeRef
integer(HRESULT_KIND)::iRet
real(FLOAT_KIND)::BaseValue
BaseValue=21.0
vVar1 = VariantCreate(VT_BYREF+VT_R4, loc(BaseValue), iRet)
vVar2 = VariantCreate(VT_BYREF+VT_VARIANT, loc(vVar1), iRet)
vVarDeRef = VariantCreate(iRet)
call VariantCopyInd(vVar2,vVarDeRef,iRet)
print *,'De-referenced variant vVarDeRef'
print *,'VT=Type (VT_R4):',vVarDeRef%varVal%vt
print *,'Value:',vVarDeRef%varVal%fltVal
stop
end
VariantCopyInd only unfolds up to two levels of indirection, which is the maximum level of variant indirection accepted by the OLE/COM standard.