I did a short test last weekend.  It appears that the following 2 procedures
are exactly the same:

type
  IntegerArray = array of Integer;

procedure A (arr: IntegerAray);
begin
  arr[0] := 1;
end;

procedure B (var arr: IntegerAray);
begin
  arr[0] := 2;
end;

var
  testdata: IntegerArray;
begin
  SetLength(testdata, 10);
  testdata[0] := 5;
  writeln (testdata[0]);
  A (testdata);
  writeln (testdata[0]);
  B (testdata);
  writeln (testdata[0]);
end.

It would appear that Delphi always passes dynamic arrays by reference.
However, because there is no copy-on-write on dynamic arrays (unlike
strings), procedure A and B have the same side effect.  So, the above will
print:

5
1
2


Regards,
Dennis.

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to