[fpc-pascal] No type info available for this type (Enumerated type with constant assignment)

2018-07-23 Thread Dennis
I am trying out the examples at 
http://wiki.freepascal.org/Enumerated_types but
The following simple program will raise compiler error "No type info 
available for this typ"


I am using Lazarus 1.8.0  FPC 3.0.4   x86_64-Win64-win32/win64


program testenum;
uses typinfo, classes, sysutils;
type
  TMonthType = (January=1, February, May=5,June, July);

var i : int32;
    s : String;
begin
  for i := Ord(Low(TMonthType)) to Ord(High(TMonthType)) do
    begin
   s:= GetEnumName(TypeInfo(TMonthType), Ord(i)); <- compiler error 
pointed at the word TypeInfo

   Writeln(i.ToSTring+' -> '+s);
    end;
  readln;
end.



However, if I change to
  TMonthType = (January, February, May,June, July);

The compiler error will disappear.

Is this kind of enumerated type with constant assignment not supported 
by FPC 3.0.4?


  TMonthType = (January=1, February, May=5,June, July);

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

Re: [fpc-pascal] No type info available for this type (Enumerated type with constant assignment)

2018-07-23 Thread Michael Van Canneyt



On Mon, 23 Jul 2018, Dennis wrote:

I am trying out the examples at 
http://wiki.freepascal.org/Enumerated_types but
The following simple program will raise compiler error "No type info 
available for this typ"


I am using Lazarus 1.8.0  FPC 3.0.4   x86_64-Win64-win32/win64


program testenum;
uses typinfo, classes, sysutils;
type
  TMonthType = (January=1, February, May=5,June, July);

var i : int32;
    s : String;
begin
  for i := Ord(Low(TMonthType)) to Ord(High(TMonthType)) do
    begin
   s:= GetEnumName(TypeInfo(TMonthType), Ord(i)); <- compiler error 
pointed at the word TypeInfo

   Writeln(i.ToSTring+' -> '+s);
    end;
  readln;
end.



However, if I change to
  TMonthType = (January, February, May,June, July);

The compiler error will disappear.

Is this kind of enumerated type with constant assignment not supported 
by FPC 3.0.4?


  TMonthType = (January=1, February, May=5,June, July);


No, only normal enumerated types can be used like that.

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

Re: [fpc-pascal] No type info available for this type (Enumerated type with constant assignment)

2018-07-23 Thread Sven Barth via fpc-pascal
Dennis  schrieb am Mo., 23. Juli 2018, 12:24:

> Is this kind of enumerated type with constant assignment not supported
> by FPC 3.0.4?
>
>TMonthType = (January=1, February, May=5,June, July);
>

The enumeration type itself is supported, however TypeInfo() and thus
GetEnumName() and friends are not.

Regards,
Sven

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

Re: [fpc-pascal] No type info available for this type (Enumerated type with constant assignment)

2018-07-23 Thread Martok
Am 23.07.2018 um 17:05 schrieb Sven Barth via fpc-pascal:
> Is this kind of enumerated type with constant assignment not supported
> by FPC 3.0.4?
> 
>    TMonthType = (January=1, February, May=5,June, July);
> 
> 
> The enumeration type itself is supported, however TypeInfo() and thus
> GetEnumName() and friends are not. 
Instead of GetEnumName, you may use ReadStr and WriteStr - the IO functions use
their separate tables, which are generated correctly even for enums with
assignments.

-- 
Regards,
Martok

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

Re: [fpc-pascal] Operator overload bug

2018-07-23 Thread Ryan Joseph


> On Jul 23, 2018, at 12:00 AM, Sven Barth via fpc-pascal 
>  wrote:
> 
> Yes, it's a bug, so please report it. 

Thanks, reported. The severity is “minor” which I guess is correct.

https://bugs.freepascal.org/view.php?id=34021

Regards,
Ryan Joseph

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

Re: [fpc-pascal] No type info available for this type (Enumerated type with constant assignment)

2018-07-23 Thread Sven Barth via fpc-pascal
Martok  schrieb am Mo., 23. Juli 2018, 17:15:

> Am 23.07.2018 um 17:05 schrieb Sven Barth via fpc-pascal:
> > Is this kind of enumerated type with constant assignment not
> supported
> > by FPC 3.0.4?
> >
> >TMonthType = (January=1, February, May=5,June, July);
> >
> >
> > The enumeration type itself is supported, however TypeInfo() and thus
> > GetEnumName() and friends are not.
> Instead of GetEnumName, you may use ReadStr and WriteStr - the IO
> functions use
> their separate tables, which are generated correctly even for enums with
> assignments.
>

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).

Regards,
Sven

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

Re: [fpc-pascal] Operator overload bug

2018-07-23 Thread Sven Barth via fpc-pascal
Ryan Joseph  schrieb am Mo., 23. Juli 2018,
17:35:

>
>
> > On Jul 23, 2018, at 12:00 AM, Sven Barth via fpc-pascal <
> fpc-pascal@lists.freepascal.org> wrote:
> >
> > Yes, it's a bug, so please report it.
>
> Thanks, reported. The severity is “minor” which I guess is correct.
>

"Minor" is the default severity. We have made the value not editable by
users, cause they'd more often than not consider their bugs as more severe
than really severe bugs.

Regards,
Sven

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

Re: [fpc-pascal] No type info available for this type (Enumerated type with constant assignment)

2018-07-23 Thread Martok
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