<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">fredvs via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> schrieb am Mi., 11. März 2020, 11:16:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello.<br>
<br>
Compiling that code with fpc 3.2.0 gives the warning that follows:<br>
<br>
--->  if (kind <> tabulatorkindty(-1)) --> gives now the warning:<br>
<br>
"msedrawtext.pas(1115,48) Warning: range check error while evaluating<br>
constants (-1 must be between 0 and 3)"<br>
<br>
tabulatorkindty is declared as:<br>
<br>
---> tabulatorkindty = (tak_left,tak_right,tak_centered,tak_decimal);<br>
<br>
So, if I understand ok, with new feature of fpc, "-1" is no more permitted<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">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. </div><div dir="auto"><br></div><div dir="auto">To highlight the problem: if the variable "kind" would contain -2 instead of -1 then your check would still fail. </div><div dir="auto"><br></div><div dir="auto">To safely convert a non-enum value (e.g. an Integer) to an enum you should use something like this:</div><div dir="auto"><br></div><div dir="auto">if (Ord(Low(TMyEnum)) <= MyInt) and (MyInt <= Ord(High(TMyEnum))) then</div><div dir="auto">  MyEnum := TMyEnum(MyInt) </div><div dir="auto">else</div><div dir="auto">  raise Exception.Create('Curse you!');</div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>