Name

VarArrayRef Function

Syntax

function VarArrayRef(const V: Variant): Variant;

Description

VarArrayRef creates a new Variant array with the varByRef bit set in the Variant’s VarType. The new Variant refers directly to the array data in V. Any changes to the dimensions or contents of V are also reflected in the new array.

VarArrayRef is a real function.

Tips and Tricks

  • Once you have created the reference, you must take care not to let the reference outlive the original array. If both Variants are in the same scope, you are fine, but do not return the reference array from a function where the original array is local to the function.

  • You cannot redimension an array reference.

Example

var
  Orig, Ref: Variant;
begin
  Orig := VarArrayCreate([1, 10], varInteger);
  Ref := VarArrayRef(Orig);
  Orig[1] := 42;
  WriteLn(Ref[1]);                      // Writes 42
  VarArrayRedim(Orig, 5);               // Also affects Ref
  WriteLn(VarArrayHighBound(Ref, 1));   // Writes 5
end;                                    // Ref and Orig are cleaned up

See Also

TVarArray Type, TVarArrayBound Type, VarArrayCreate Function, VarArrayDimCount Function, VarArrayHighBound Function, VarArrayLock Function, VarArrayLowBound Function, VarArrayOf Function, VarArrayRedim Procedure, VarArrayUnlock Function, Variant Type, VarIsArray Function, VarType Function
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset