Hello fredvs,
you wrote on Wed, 11 Mar 2020 02:22:07 -0700 (MST):
> Here a example maybe more clear:
Let's see...
> msedrawtext.pas(1115,48) Warning: range check error while evaluating
> constants (-1 must be between 0 and 3)
>
> This warning point to:
>
> ---> if (kind <> tabulatorkindty(-1))
>
> and tabulatorkindty is declared as:
>
> ---> tabulatorkindty = (tak_left,tak_right,tak_centered,tak_decimal);
So the type of the cast is an enumeration type, an ordinal value, that,
basically, will not be negative usually. It might even be regarded as not
having a value in the first place, but just specifying an arbitrary
ordering (hence the name "ordinal").
> So, if I understand ok, with new feature of fpc, "-1" is no more permitted
> as default.
This is not a "new feature", but a design principle.
It might be seen as a "new feature" that the use of an out-of-bounds value
for an enumeration mamber is flagged as a warning. (If it's not appearing
simply because in this specific code area the pertinent warning is for some
reason no longer disabled.)
> What do you think, must a new constant be added in the array, this for the
> default value, something like:
>
> ---> tabulatorkindty = (tak_left,tak_right,tak_centered,tak_decimal,
> tak_none);
There's a simple way to resolve this: You got to throw good Pascal design
principles over bord and introduce mainly, let's say, type indifferent C
usage. In this case, you ought to apply the "assigned enumeration" type
"extension" of fpc, which allows you to _define_ enumeration menmber's
values explicitely instead of enumerating them sequentially.
(fpc reference manual, Types - Base types - Ordinal types - Enumeration
types.)
> ?
Yes, that is plain type ignorant C style.
> And then initialize it with:
>
> ---> if (kind <> tabulatorkindty(tak_none) ?
Maybe, the name of this queer member ist unimportant, you may use this
name, if only you _assign_ it the value you want it to represent. I.e. you
had to define the extended enumeration like this:
tabulatorkindty = (tak_none:= -1, tak_left{:= 0, but that's so anyway},
tak_right, tak_centered,tak_decimal);
That way, everything keeps its well known order and value, and the new
value is added as a _legal_ member of the sequence, even with the
"illegally" added extraneous value used in the statement causing the
warning. This can even be written without the cast then, because it now
references a _legal_ member of the type:
if (kind <> tak_none) ...
> If so, maybe **lot of** work because Martin did use "-1" in many case.
He seems not having been aware of this extension to the enumeration type,
then. (It's part of fpc's definition since at least version 2.1!)
Doing it this way, the amount of required work should not be so enormous.
Only the type definitions where such constructs are used need to be fixed.
(You might even decide to keep the casts from -1 to save on modifications.)
BTW, I'd suggest to use the word "illegal" (or maybe "undefined") as the
base name for these extraneous additional enumeration members, like, for
the example above:
tabulatorkindty = (tak_illegal:= -1, tak_left, tak_right,
tak_centered,tak_decimal);
resulting in
if (kind <> tak_illegal) ...
for the example use, which might even better represent its intention, too.
--
--
(Weitergabe von Adressdaten, Telefonnummern u.ä. ohne Zustimmung
nicht gestattet, ebenso Zusendung von Werbung oder ähnlichem)
-----------------------------------------------------------
Mit freundlichen Grüßen, S. Schicktanz
-----------------------------------------------------------
_______________________________________________
mseide-msegui-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk