Can E2064 be disabled in Delphi XE4?

228 views Asked by At

I have the following sample code in my DUnitX test project that fails to compile. This sample code is scoped identically to code that compiles without errors in a very large VCL forms project. Both projects are using Delphi XE4, yet when I reference the source file that compiles successfully in the VCL project in my DUnitX unit test project, it fails with the same E2064 left side cannot be assigned to this code produces:

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

type
  TTestRec = record
    A: string;
  end;

const
  AConstArray : array [0..1] of TTestRec = ( (A: '1'), (A: '2') );

procedure E2064Test;
begin
  {$J+}
  {$WRITEABLECONST ON}
  AConstArray[0].A := '3'; // error here
  AConstArray[1].A := '4'; // error here
  {$WRITEABLECONST OFF}
  {$J-}
end;

begin
end.

Is there a compiler switch or some other strange path/setting that I need to specify to get this code to compile for my DUnitX test project in XE4?

2

There are 2 answers

4
Graymatter On BEST ANSWER

You can use {$J+}. This compiles for me.

type
  TTestRec = record
    A: string;
  end;

const
  {$J+}
  AConstArray : array [0..1] of TTestRec = ( (A: '1'), (A: '2') );
  {$J-}

procedure E2064Test;
begin
  AConstArray[0].A := '3'; // error here
  AConstArray[1].A := '4'; // error here
end;
3
John Kaster On

With the help of Graymatter, I found the place to set the switch.

Click the checkbox under:

Project options | Delphi compiler | Compiling | Syntax | Assignable types constants

Update: As graymatter points out, the compiler switches, if used, need to be where the symbol is declared, not accessed.