How about following the same schema as with classes?

If 1 is TMyEnum then
  //use hard cast here


> -----Original Message-----
> From: fpc-devel <fpc-devel-boun...@lists.freepascal.org> On Behalf
> Of Ondrej Pokorny
> Sent: Saturday, 14 April 2018 18:32
> To: fpc-devel@lists.freepascal.org
> Subject: Re: [fpc-devel] Dangerous optimization in CASE..OF
> 
> On 14.04.2018 10:24, Michael Van Canneyt wrote:
> > On Sat, 14 Apr 2018, Ondrej Pokorny wrote:
> >
> >> Effectively, you should be able to use:
> >> var
> >>   E: TMyEnum;
> >> begin
> >>   if TryIntToEnum(1, E) then
> >>
> >> instead of
> >>   if TryIntToEnum(TMyEnum, 1, E) then
> >
> > I am all for it, although I think the "as" syntax is more elegant,
> and
> > that has my preference.
> 
> I am for both variants. If you want the "hard check" with exception
> on error you use the "as" syntax, whereas if you want the "soft
> check" with boolean result, you use TryIntToEnum.
> 
> IntToEnum could be added as an alternative to the "as" syntax for
> the sake of consistency, if the demand is present.
> 
> But with my experience and knowledge of the compiler, the
> TryIntToEnum variant will be harder to implement for me. I am a
> little bit struggling with it.
> 
> Ondrej
> _______________________________________________
> fpc-devel maillist  -  fpc-devel@lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to