I copied some Delphi code from one project to another, and found that it doesn’t compile in the new project, though it did in the old one. The code looks something like this:
procedure TForm1.CalculateGP(..) const Price : money = 0; begin ... Price := 1.0; ... end;
So in the new project, Delphi complains that ‘left side cannot be assigned to’ – understandable! But this code compiles in the old project. So my question is, why? Is there a compiler switch to allow consts to be reassigned? How does that even work? I thought consts were replaced by their values at compile time?
You need to turn assignable typed constants on. Project -> Options -> Compiler -> Assignable typed Constants
Also you can add
{$J+}or{$WRITEABLECONST ON}to the pas file, which is probably better, since it’ll work even if you move the file to another project.