[fpc-pascal] Illegal expression when redeclare typed constant

Sven Barth pascaldragon at googlemail.com
Sun Mar 26 11:23:56 CEST 2023


Zamrony P. Juhara via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb
am So., 26. März 2023, 00:05:

> Suppose  I have
>
> unit mytest;
>
> interface
>
> const
>     MY_VALUE = 1;
>     MY_INT_VALUE: integer = 1;
>
> implementation
> end.
>
> and second unit
>
> unit mytest2;
>
> interface
>
> uses mytest;
>
> const
>     // this is legal
>     MY_VALUE = mytest.MY_VALUE;
>
>     // this  causes illegal expression
>     // MY_INT_VALUE = mytest.MY_INT_VALUE;
>     // MY_INT_VALUE : integer = mytest.MY_INT_VALUE;
>
> implementation
> end.
>
>
> Is there workaround to redeclare typed constant in other unit so that I
> don't need to duplicate code?
>

Typed constants are essentially variables and you can't redeclare
variables.

Only way you might do that (which I do not recommend because it opens it's
own can of worms) is to declare the original variable as "public" and to
import it in the other unit using "external".

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230326/a8c9a25c/attachment.htm>


More information about the fpc-pascal mailing list