Delphi compiler error. The left side of the E2064 cannot be assigned

I have inherited the Delphi application and I know nothing about the pascal object.

This is the BPL that I need to compile into a new version of C ++ Builder XE.
When I run make, I get an error:

The left side of the E2064 cannot be assigned.

I learned obj pascal enough to know that I have a constant that is trying to assign a value.

But, apparently, you can overcome this behavior; essentially turning constants into vars by going to the Build options under the Delphi compiler and turning on "Assignable Typed constants".

I did this and I keep getting the same error.

I tried to surround my code with {$ J +} and {$ J-}, and it still won’t 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 message on the last line. If I change const to var, I get an error that is different from the previous declaration, but I have no idea where the previous declaration is ...

+4
source share
3 answers

You enter a two-byte thing ( Char ) into a one-byte thing ( Byte ). The reading of this value is easy to determine, but making this value valid for writing is difficult, perhaps for the same reason the types of the formal and actual "var" parameters must be identical.

Maybe you would like to inject it into a two-byte thing like Word . Or maybe you want the GammaTable be a Char array, so you don't have to type at all. Or maybe if this code was originally written for the Delphi version before 2009, you want those PChar declarations to be PAnsiChar - the character types are wider. Another option is to type-cast Dest to PByte , and then cast the result. Perhaps this is a bad idea, because you will only rewrite each byte of the buffer.

Based on the function name, it looks like PChar never the right data type. This type is for character data, but I think this code deals with bytes. The right thing probably is to change PChar to PByte , and then you don't need to type Dest at all.

The $J directive does not matter; it controls whether the compiler allows assignment of values ​​to typed constants. In this code you do not have a single one.

+8
source

It looks like you are working with the Gustavo Daud TPngImage library. You do not need this code in an external BPL, as it has been included in RTL since D2009. Remove this block from the BPL and you can get the updated version using the PngImage block.

+1
source

The reason is that since Delphi 2009, Char, PChar and String are Unicode and store more than one byte per character.
You should not point these pointers to bytes, and the compiler does not allow you to assign them if you give the left part of the job to a byte.

This compiles:

 procedure CopyInterlacedRGB8(const Pass: Byte; Dest: pAnsiChar); overload; begin Byte(Dest^) := Pass; end; 

It does not mean:

 procedure CopyInterlacedRGB8(const Pass: Byte; Dest: pChar); overload; begin Byte(Dest^) := Pass; end; 

Instead of pChar, you should use pByte, which makes the code simpler:

 procedure CopyInterlacedRGB8(const Pass: Byte; Dest: PByte); overload; begin Dest^ := Pass; end; 

- Jeroen

+1
source

All Articles