Left side cannot be assigned to delphi ошибка

I inherited a Delphi application and I know nothing about object pascal.

It’s a BPL that I need to compile into the new version of C++ Builder XE.
When I run a make I get the error:

E2064 left side cannot be assigned to.

I’ve learned enough obj pascal to know I have a constant that is trying to be assigned a value.

But, apparently, you can over ride this behanvior; essentially turning constants into vars by going into Build options under the Delphi compiler and turning on «Assignable Typed constants».

I did that and I continue to get the same error.

I tried surrounding my code with {$J+} and {$J-} and still it will not compile.

procedure TChunkIDAT.CopyInterlacedRGB8(const Pass: Byte;
  Src, Dest, Trans{$IFDEF Store16bits}, Extra{$ENDIF}: pChar );
var
  Col: Integer;
 begin
 {Get first column and enter in loop}
 Col := ColumnStart[Pass];
 Dest := pChar(Longint(Dest) + Col * 3);
 repeat
 {Copy this row}

  Byte(Dest^) := fOwner.GammaTable[pByte(Longint(Src) + 2)^]; inc(Dest);

Get the error on last line. If I change the const to a var, I then get the error that the declaration differs from the previous declaration but I have no idea where the previous declaration is….

Go Up to Error and Warning Messages (Delphi)

This error message is given when you try to modify a read-only object such as a constant, a constant parameter, the return value of function, read-only properties, or fields of read-only properties.

There are two ways you can solve this kind of problem:

  • Change the definition of whatever you are assigning to, so the assignment becomes legal.
  • Eliminate the assignment altogether.

Examples

program Produce;

const
  c = 1;

procedure p(const s: string);
begin
  s := 'changed';            (*<-- Error message here*)
end;

function f: PChar;
begin
  f := 'Hello';              (*This is fine - we are setting the return value*)
end;

begin
  c := 2;                    (*<-- Error message here*)
  f := 'h';                  (*<-- Error message here*)
end.

The previous example assigns to a constant parameter, to a constant, and to the result of a function call. All of these are illegal. The following example illustrates how to fix these problems.

program Solve;

var
  c : Integer = 1;           (*Use an initialized variable*)

procedure p(var s: string);
begin
  s := 'changed';            (*Use variable parameter*)
end;

function f: PChar;
begin
  f := 'Hello';              (*This is fine - we are setting the return value*)
end;

begin
  c := 2;
  f^ := 'h';                 (*This compiles, but will crash at run time*)
end.

In Delphi 2010 and above, E2064 is also emitted by the compiler whenever you try to assign a value to a member of a record exposed by a read-only property. Consider the following record type:

TCustomer = record
  Age: Integer;
  Name: String;
end;

that is exposed by a read-only property in a class:

TExposing = class
...
  CurrentCustomer: TCustomer read SomeInternalField;
...
end;

Assigning a value to either the CurrentCustomer property or to a member of the record exposed by the CurrentCustomer property results in the compiler emitting this E2064 error.

Posted by jpluimers on 2021/05/27

Quoting this in full because it nicely illustrated the introduction of an intermediate variable that cannot be assigned to a second time after initial setup by the with statement: [WayBack] Embarcadero Newsgroup Archive :: embarcadero.public.delphi.ide :: Re: Delphi 2010 Compile error E2064 Left side cannot be assigned to.

Subject: Re: Delphi 2010 Compile error E2064 Left side cannot be assigned to
Posted by: Uwe Schuster (jediv…@bitcommander.de)
Date: Sat, 10 Oct 2009

Finn Tolderlund wrote:

> I get this error in Delphi 2010 with the code below:
> But if I remove the () from the line, it compiles and executes ok.
> Is it a bug in the compiler?
> …
with (Pal.palPalEntry[i]) do  // Compile error: E2064 Left side cannot be assigned to
with Pal.palPalEntry[i] do  // Works fine

This is no bug, because the parenthesis generates an intermediate
non-addressable value and D2010 does not longer allow write access to intermediate values with “with”.


Uwe

This also might explain Delphi 10.2 Tokyo introduced a “with” warning: for most “with” statements, W1048 is raised ([RSP-17326] with statements generate W1048 unsafe typecast warning – Embarcadero Technologies), assuming that the intermediate is a pointer variable.

–jeroen

This entry was posted on 2021/05/27 at 06:00 and is filed under Delphi, Development, Software Development.
You can follow any responses to this entry through the RSS 2.0 feed.

You can leave a response, or trackback from your own site.

Your variable FBoundsRect is of type TRectF which is a record. Records are passed by value, not by reference. Meaning: When you access TempResult.BoundsRect, you are not acting on the original data, but a copy on it.

Yes, in theory, you can access and modify the temporary data, but the compiler does not let you as it makes no sense to do so. The compiler message is unfortunately, once again, not helpful.

One solution is storing it in a temporary local variable, and then assigning it back, after you have changed the bounds rect.

Another one is getting rid of the the properties altogether as they just add noise and hide the fact that you can just replace the complete record, but not just parts of it, as you desire.

program Project1;

uses System.SysUtils, System.Types;

type
	TMyObject = class(TObject)
		strict private var _PropField: TRectF;
		public property PropField: TRectF read _PropField write _PropField;
		public var VarField: TRectF;
	end;

var
	myObject: TMyObject;
begin
	myObject := TMyObject.Create();
	myObject.VarField.Left := 12.0;
	myObject.PropField.Left := 12.0; // E2064 LEft side cannot be assigned to
end.


Edited by Der schöne Günther

 
worldmen
 
(2010-05-06 21:28)
[0]

Решил попробовать преревести прогу в Delphi 2010. При компиляции выводит ошибку:
[DCC Error] ice.pas(581): E2064 Left side cannot be assigned to
Строка:

type
 TKoordinate = object
   x, y, x2, y2 : integer;
 end;
....
Var SStop : TKoordinate;
...
procedure ...
begin
SStop.y:=Screen.Height - 50;


end;
В чем проблема?


 
worldmen
 
(2010-05-06 21:30)
[1]

Забыл. Ругается на строку
SStop.y:=Screen.Height - 50;


 
Игорь Шевченко ©
 
(2010-05-06 22:06)
[2]

TKoordinate = record


 
Loginov Dmitry ©
 
(2010-05-06 22:11)
[3]


> В чем проблема?

На пустом проекте все прекрасно скомилировалось. Может какие опции компиляции выставлены? (object в Delphi популярностью не пользуется).


 
worldmen
 
(2010-05-11 10:31)
[4]

Еще кое-что забыл. Тут видимо неправильно я свойство использую:

TMyIniFile = record
   Login         : TButText;
   Undok,  SelectAll,    SelectAllTo,  ShieldB :  TKoordinate;  
   Zakladki  :  TKoordinate2;  
   Stantion :  integer;      
   FileIni    : String;        
 end;

TForm1 = class(TForm)
...
private
   FVarIniF :  TMyIniFile;
public
   property  varIniF   : TMyIniFile read FVarIniF;

implementation

procedure ...
begin
 with varIniF do begin
   SStop.y:=Screen.Height - 50;  // - тут ругается
...
end;

[DCC Error] ice.pas(581): E2064 Left side cannot be assigned to


 
Плохиш ©
 
(2010-05-11 10:53)
[5]


> worldmen   (11.05.10 10:31) [4]
>
> Еще кое-что забыл.

и привёл опять куски несвязного кода. Вспоминай дальше.
Приведённый дерьмокод такой ошибки не вызывает.


 
Омлет ©
 
(2010-05-11 10:56)
[6]

Замени
> with varIniF do begin

на
> with FVarIniF do begin


 
Плохиш ©
 
(2010-05-11 10:57)
[7]

PS. Но так как я сегодня добрый, то скажу
такое объявление

>    property  varIniF   : TMyIniFile read FVarIniF;

не позволит изменить данное свойство не только в d2010, но и в d7


 
worldmen
 
(2010-05-12 10:44)
[8]

> Плохиш ©   (11.05.10 10:57) [7]
> PS. Но так как я сегодня добрый, то скажутакое объявление
> >    property  varIniF   : TMyIniFile read FVarIniF;не позволит
> изменить данное свойство не только в d2010, но и в d7

Я проверил (протрассировал) — все работает и не выдает ошибки в Delphi 7.
Спасибо за подсказку Омлет —
with FVarIniF do begin
все получилось


Понравилась статья? Поделить с друзьями:
  • Launchtm exe ошибка приложения
  • Launchgtaiv exe ошибка приложения
  • Launcherrsxruntime exe ошибка
  • Laravel коды ошибок
  • Launcherpatcher exe ошибка при запуске приложения 0xc000007b