On 24 Oct 2008, at 21:51, Valdas Jankūnas wrote:

const
 MAX_LAIKO_JUOSTA: TLaikoJuosta=(Valanda: 99; Minute: 59);

I want create another constant:

MAX_LAIKO_JUOSTA_MINUTEMIS=MAX_LAIKO_JUOSTA.Valanda*MinsPerHour +MAX_LAIKO_JUOSTA.Minute;

But compiler (I working in Lazarus v0.9.27 r16994 i386-linux-gtk 2 (beta); fpc 2.2.2) reported "Error: Illegal expression" and cursor blinks at end of line of new constant. Same error if I try:

MAX_LAIKO_JUOSTA_MINUTEMIS: SmallInt=MAX_LAIKO_JUOSTA.Valanda*MinsPerHour+MAX_LAIKO_JUOSTA.Minute;

I creating constant from a constant. But why I getting that error?

Because a "typed constant" is a bad name chose by Borland for "initialised variable". And you cannot use variables (initialised or not) in constant expressions.

With {$j-} typed constants become real constants (they cannot be changed anymore, unlike in the default {$j+} state), but even then the above probably won't work because while parsing the compiler directly writes the values of such constants/initialised variables in the assembler list rather than constructing some semantic entity which can be reused later (so the compiler has no way to retrieve the values of such constants when you try to reuse them later on).


Jonas_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to