Am 23.07.2018 um 19:47 schrieb Sven Barth via fpc-pascal:
> Though you'll get an access violation if you use a value that's not part of 
> the
> enum (in the example this will happen when the loop reaches the value 3).
Not an AV - an IOError, so it's easy and safe to catch.

I use stuff like this, with aValue being of a generic type:
  {$IOChecks OFF}
  WriteStr(Result, aValue);
  if IOResult = 107 then
    Result:= '';

  ReadStr(aStr, a);
  Result:= IOResult <> 106;
  if Result then
    aValue:= a;

Turns out this is currently also the *only* typesafe way to check if an
arbitrary ordinal is a valid member of an enum type. But that's a different
story ;-)

-- 
Regards,
Martok

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

Reply via email to