[fpc-pascal] EnumToString

Yann Bat batyann811 at gmail.com
Tue Nov 1 08:53:40 CET 2011


You can directly write enums with Write or WriteLn and convert enums
to strings with WriteStr.

program EnumStr;
{$mode objfpc}{$H+}

type
  TColor = (cRed, cGreen, cBlue, cYellow);

function ColorToStr(C: TColor) : String;
begin
  WriteStr(Result, C);
end;

var
  Color : TColor;
begin
  for Color in TColor do
    WriteLn(ColorToStr(Color));
end.

2011/11/1 Juha Manninen <juha.manninen62 at gmail.com>:
> Hi
> I remember there is a way to get a string representation of an enumerated
> type directly without using a lookup string array, but I forgot the syntax.
> Lazarus uses only lookup arrays, maybe because the other syntax is new.
> How is the syntax?
> Juha
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



More information about the fpc-pascal mailing list