Search code examples
delphidelphi-xe6

Odd compilation error message


The following snippet, in XE6

procedure TForm1.Test(CDS : TClientDataSet);
var
  AGuid : TGuid;
  lResult : Longint;
begin
  lResult := SysUtils.CreateGUID(AGuid);
  CDS.InsertRecord([AGuid, '', False]);
end;

produces the error message

[dcc32 Error] Unit1.pas(73): E2150 Bad argument type in variable type array constructor

Fwiw, in discovering this, I was trying to retrace my steps to a previous version of this routine where the compiler was generating the error

E2197 Constant object cannot be passed as var parameter 

on the line

  lResult := SysUtils.CreateGUID(AGuid);

despite the fact that what was provoking it turned out to be an error in the subsequent code.


Solution

  • This is the declaration of the InsertRecord method:

    procedure InsertRecord(const Values: array of const);
    

    The parameter is a variant open array. Variant open array parameters are implemented internally by being passed as TVarRec instances. And TVarRec cannot contain records. Since TGUID is a record, it cannot be passed in a variant open array parameter.