fork download
  1. {$mode objfpc}
  2. {$modeswitch typehelpers}
  3. {$M+}
  4.  
  5. uses typinfo;
  6.  
  7. type
  8. TRoosters = (GoldenRooster, Junglefowl, FightingCock, Fjalarr, Gullinkambi, GallicRooster, You);
  9.  
  10. TTestPituh = class(TObject)
  11. private
  12. TestField: TRoosters;
  13. published
  14. property TestProp: TRoosters read TestField write TestField;
  15. end;
  16.  
  17. TRoostersHelper = type helper for TRoosters
  18. public
  19. function GetRoosterName: string;
  20. end;
  21.  
  22. function TRoostersHelper.GetRoosterName: string;
  23. begin
  24. GetRoosterName := GetEnumName(GetPropInfo(TTestPituh,'TestProp')^.PropType, LongInt(self))
  25. end;
  26.  
  27. begin
  28. Writeln(FightingCock.GetRoosterName)
  29. end.
Success #stdin #stdout 0s 660KB
stdin
Standard input is empty
stdout
FightingCock