Hello
I just picked up Pascal/Lazarus after using Delphi more than 10 years ago.
Trying to run some samples, I stumbled across an error when using a constant in the declaration of another constant, see following mwe:
Program Example;
Const
x: Integer = 42;
y: Integer = x;
Begin
writeln('Hello');
End.
I get the following output when compiling with "fpc example.pas":
Free Pascal Compiler version 3.2.2 [2021/07/09] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling example.pas
example.pas(6,17) Error: Illegal expression
example.pas(11) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode
If I replace the x in y's definition with the literal value it compiles fine.
Now I have three questions:
1. Why does this error occur when using the constant but not when using a literal?
2. How can I fix this?
3. Is there maybe another (more idiomatic?) way to achieve the same result?