Name

VarIsArray Function

Syntax

function VarIsArray(const V: Variant): Boolean;

Description

VarIsArray returns True if the Variant V is an array, and it returns False otherwise. A Variant array has the varArray bit set in its VarType.

VarIsArray is a real function.

Example

// Return the sum of all the numbers in a 1D array, or if the
// argument is not an array, return its numeric value.
function Sum(const V: Variant): Variant;
var
  I: Integer;
begin
  if VarIsArray(V) then
  begin
    Result := 0.0;
    Assert(VarArrayDimCount(V) = 1);
    for I := VarArrayLowBound(V, 1) to VarArrayHighBound(V, 1) do
      Result := Result + V[I];
  end
  else
    Result := V + 0.0; // Ensure that the result is numeric.
end;

See Also

TVarArray Type, TVarArrayBound Type, VarArrayCreate Function, VarArrayDimCount Function, VarArrayHighBound Function, VarArrayLock Function, VarArrayLowBound Function, VarArrayOf Function, VarArrayRedim Procedure, VarArrayRef Function, VarArrayUnlock Function, Variant Type, VarIsArray Function, VarType 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.