Recent

Author Topic: TypeInfo for Enum with Value  (Read 330 times)

Okoba

  • Hero Member
  • *****
  • Posts: 648
TypeInfo for Enum with Value
« on: February 03, 2026, 08:57:06 am »
Hello,

I get an error for TTest2 on the latest FPC as "Error: No type info available for this type". Is there a way to get TypeInfo for it?
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. uses
  4.   TypInfo;
  5.  
  6. type
  7.   {$M+}
  8.   TTest1 = (t1A, t1B);
  9.   TTest2 = (t2A = 5, t2B = 10);
  10. begin
  11.   WriteLn(GetEnumNameCount(TypeInfo(TTest1)));
  12.   WriteLn(GetEnumNameCount(TypeInfo(TTest2)));
  13.   ReadLn;
  14. end.
  15.  

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 383
  • I use FPC [main] 💪🐯💪
Re: TypeInfo for Enum with Value
« Reply #1 on: February 03, 2026, 09:34:02 am »
D12.1CE:
Code: Pascal  [Select][+][-]
  1. E2134 Type 'TTest2' has no type info
I may seem rude - please don't take it personally

Zvoni

  • Hero Member
  • *****
  • Posts: 3246
Re: TypeInfo for Enum with Value
« Reply #2 on: February 03, 2026, 09:45:05 am »
I know: Wiki is not documentation, but it's the only place i found something
https://wiki.freepascal.org/Enum_type
Quote
Properties

    An enumeration data type definition is ascending if the difference in ordinal value to every right-hand member is ≥ 1. Currently, non-ascending definitions merely emit a note. A set literal using two enumeration values having the same ordinal value, albeit represented by different symbols, will not be accepted.
    An enumeration data type is contiguous if the ordinal value of every (named) member has an absolute difference of one to its neighbors. Using a set constructor on a non-contiguous enumeration data type may produce unexpected results.
    An enumeration data type is normal if it is ascending and contiguous and the first member has an ordinal value of (strictly speaking) zero, or, in the broad sense (as implemented by the FPC), ≤ 0. The compiler intrinsic typeInfo is only available for those enumeration data types.

Because this works. all other combinations fail
Code: Pascal  [Select][+][-]
  1. type
  2.   {$M+}
  3.   TTest1 = (t1A, t1B);
  4.   TTest2 = (t2A = -1, t2B = 0, t2C = 1);  //<--
  5. begin
  6.   WriteLn(GetEnumNameCount(TypeInfo(TTest1)));
  7.   WriteLn(GetEnumNameCount(TypeInfo(TTest2)));
  8.   ReadLn;
  9. end.          
« Last Edit: February 03, 2026, 09:58:15 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

PascalDragon

  • Hero Member
  • *****
  • Posts: 6315
  • Compiler Developer
Re: TypeInfo for Enum with Value
« Reply #3 on: February 03, 2026, 11:03:32 pm »
I get an error for TTest2 on the latest FPC as "Error: No type info available for this type". Is there a way to get TypeInfo for it?

Enumeration types with holes in them do not have type information. This is Delphi-compatible.

 

TinyPortal © 2005-2018