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….
You’re type-casting a two-byte thing (
Char) into a one-byte thing (Byte). Reading that value is easy to define, but making that value writable is tricky, probably for the same reason the types of formal and actual “var” parameters need to be identical.Maybe you wanted to type-cast it to a two-byte thing, such as
Word. Or maybe you wantGammaTableto be an array ofCharso you don’t have to type-cast at all. Or maybe, if this code was originally written for a Delphi version earlier than 2009, you want thosePChardeclarations to bePAnsiChar— character types have gotten wider. Another option is to type-castDesttoPByte, and then dereference the result. That’s probably a bad idea, though, because you’ll only be overwriting every other byte of the buffer.Based on the name of the function, it sounds like
PCharwas never the right data type to use. That type is for character data, but I think this code is dealing with bytes. The correct thing to do is probably to changePChartoPByte, and then you don’t need to type-castDestat all.The
$Jdirective is irrelevant; it controls whether the compiler will allow you to assign values to typed constants. You don’t have any of those in this code.