fredvs via fpc-pascal <fpc-pascal@lists.freepascal.org> schrieb am Mi., 11. März 2020, 11:16:
> Hello. > > Compiling that code with fpc 3.2.0 gives the warning that follows: > > ---> if (kind <> tabulatorkindty(-1)) --> gives now the warning: > > "msedrawtext.pas(1115,48) Warning: range check error while evaluating > constants (-1 must be between 0 and 3)" > > tabulatorkindty is declared as: > > ---> tabulatorkindty = (tak_left,tak_right,tak_centered,tak_decimal); > > So, if I understand ok, with new feature of fpc, "-1" is no more permitted > By definition an enum value can only contain the values that are listed in its declaration, anything else is an invalid value. If it contains another value then you have already made a mistake when converting some other type to the enum. To highlight the problem: if the variable "kind" would contain -2 instead of -1 then your check would still fail. To safely convert a non-enum value (e.g. an Integer) to an enum you should use something like this: if (Ord(Low(TMyEnum)) <= MyInt) and (MyInt <= Ord(High(TMyEnum))) then MyEnum := TMyEnum(MyInt) else raise Exception.Create('Curse you!'); Regards, Sven >
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal