XE7’s new dynamic array syntax – take 2

XE7’s new dynamic array syntax – take 2

The syntax change also introduced a new ambiguity between argument types array of type and array of const.

Not sure that it is the appropriate error – as you should not be able to pass [] as an argument to a var parameter?

program XE7Tests2;

{$APPTYPE CONSOLE}

{$R *.res}

uses

  System.SysUtils, Variants;

type

  TVarArray = array of Variant;

  TTest = class

    function StoredProc(ConstParams: array of const): integer; overload;

    function StoredProc(var Params: TVarArray): integer; overload;

  end;

{ TTest }

function TTest.StoredProc(ConstParams: array of const): integer;

begin

end;

function TTest.StoredProc(var Params: TVarArray): integer;

begin

end;

var

  Test: TTest;

begin

  Test := TTest.Create;

  try

    try

      Test.StoredProc([]);  

// [dcc32 Error]: E2251 Ambiguous overloaded call to ‘StoredProc’

// Related method: function TTest.StoredProc(array of const): Integer;

// Related method: function TTest.StoredProc(var TVarArray): Integer;

    except

      on E: Exception do

        Writeln(E.ClassName, ‘: ‘, E.Message);

    end;

  finally

    Test.Free;

    Write(‘ – Enter: ‘);

    Readln;

  end;

end.

3 thoughts on “XE7’s new dynamic array syntax – take 2


  1. Overload resolution is based on type, and I guess the compiler can’t figure the type of [], as it could be an array (or set) of anything, so it needs to be supported as a special case.

Leave a Reply