Name

VarAsType Function

Syntax

function VarAsType(const V: Variant; VarType: Integer): Variant;

Description

VarAsType performs a typecast of V to a new Variant type. VarType must not contain the varArray or varByRef bits. If V cannot be converted to the desired type, VarAsType reports runtime error 15 (EVariantError).

VarAsType is a real function.

Tips and Tricks

  • VarAsType is a functional version of VarCast. If you want to assign the result to an OleVariant, you should use VarCast instead, because it performs additional type checking.

  • If the type of Source is already VarType, VarAsType performs a simple copy.

Example

Int := 1;
Float := VarAsType(Int, varDouble);

See Also

OleVariant Type, TVarData Type, VarCast Procedure, VarCopy Procedure, Variant Type, VarIsArray Function, VarIsEmpty Function, VarIsNull Function

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.