Re: [fpc-pascal] Illegal expression when redeclare typed constant

2023-03-26 Thread Sven Barth via fpc-pascal
Zamrony P. Juhara via fpc-pascal  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

>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Illegal expression when redeclare typed constant

2023-03-25 Thread Zamrony P. Juhara via fpc-pascal
Suppose  I have
unit mytest;
interface
const    MY_VALUE = 1;    MY_INT_VALUE: integer = 1;
implementationend.
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;
implementationend.

Is there workaround to redeclare typed constant in other unit so that I don't 
need to duplicate code?
Thanks
Zamrony P. Juharahttps://juhara.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal