title: Reference a Delphi variant array without copying
body: <p>This might seem like a strange request, but there is a good reason (code generation application). I pass a variant array to a procedure, contained within an array of variants, as follows:</p>
  
  <pre><code>TVarArray = array of variant;
  
  procedure TMainForm.Button1Click(Sender: TObject);
  var
    params: TVarArray;
    numRows: integer;
    numCols: integer;
    i: integer;
    j: integer;
  begin
    SetLength(params, 2);
    numRows := 2;
    numCols := 2;
  
    params[0] := 5;
    params[1] := VarArrayCreate([1, numRows, 1, numCols], varVariant);
    for i := 1 to numRows do
      for j := 1 to numCols do
        params[1][i, j] := i + j;
  
    TestProc(params);
  end;
  
  procedure TMainForm.TestProc(params: TVarArray);
  var
    arr: variant;
    p: PVariant;
    v: variant;
  begin
    arr := params[1];    // -- Copies the array to arr.
    arr[2, 2] := 99;
  
    p := @(params[1]);
    p^[2, 2] := 88;      // -- Directly reference the passed-in array.
  
    v := p^;             // -- Copies the array to v -&gt; How to prevent?
    v[2, 2] := 77;       // -- This should change the value in the original array.
  
    edit1.Text := VarToStr(arr[2, 2]);             // -- 99
    edit2.Text := VarToStr(params[1][2, 2]);       // -- 88  - should be 77
    edit3.Text := VarToStr(v[2, 2]);               // -- 77
  end;
  </code></pre>
  
  <p>I don't want to create a copy of the array, so could use p^[] to directly access the passed-in array. However, I don't want to use the p^ syntax in TestProc but would prefer to use a variable name without the ^. Of course, if I try v := p^ I just get a copy. Is there any way around this? Thanks!</p>