Search code examples
delphidelphi-xe4dcc32

Can E2064 be disabled in Delphi XE4?


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?


Solution

  • 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;