[fpc-pascal] How can you convert an enum value to string?

silvioprog silvioprog at gmail.com
Sat Dec 13 03:50:37 CET 2014


Oops, sorry, <raw> tag on nabble platform cutted my code. :S

On Fri, Dec 12, 2014 at 11:46 PM, silvioprog <silvioprog at gmail.com> wrote:
>
> But if you want speed in your conversion, GetEnumName is more fast than
> WriteStr. :3


uses
  typinfo;

type
  tenum = (e1, e2, e3);

procedure TForm1.Button1Click(Sender: TObject);
const
  c = 10000000;
  m = 'hh:nn:ss:zzzz';
var
  i: integer;
  en: tenum;
  s, r: string;
  b, e: tdatetime;
begin
  en := e2;
  b := now;
  for i := 1 to c do
    writestr(s, en);
  e := now;
  r := formatdatetime(m, e - b);
  e := b;

  b := now;
  for i := 1 to c do
    getenumname(typeinfo(tenum), integer(en));
  e := now;

  r += ' - ' + formatdatetime(m, e - b);

  ShowMessage(r);
end;

Result:
>
> 00:00:04:336 - 00:00:01:407


-- 
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20141212/22a28e33/attachment.html>


More information about the fpc-pascal mailing list