[fpc-pascal] Using constants in constant record definition

Jonas Maebe jonas at freepascal.org
Wed Jun 12 22:37:54 CEST 2019


On 12/06/2019 22:25, Simon Ameis wrote:

> const
>    MYRECORDCONST2: TMyRecord = (x: 5); //< compiles fine
>    MYINTEGERCONST: Integer = 5;        //< defining integer const
>    MYRECORDCONST1: TMyRecord = (x: MYINTEGERCONST); //< using constant is
> no possible

For historical reasons, "MYINTEGERCONST: Integer = 5" does not declare a 
constant, but an initialised variable. To declare a constant, use

const
   MYINTEGERCONST = 5;

If you want to explicitly specify its type, you can use

const
   MYINTEGERCONST = Integer(5);


Jonas


More information about the fpc-pascal mailing list