Enum values to string lazarus / 61-Beginners ---------------------------------------------------------------------- Nitorami · 2016-03-22 19:58 Hi A simple question: Can I convert enums to string ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type TDays = (mon,tue,weg,thu,fri,sat,sun); var ThisDay: TDays;    s: string; begin  ThisDay := tue;  writeln (ThisDay); //this works  s := ThisDay; // but this notend. ---------------------------------------------------------------------- balazsszekely · 2016-03-22 20:06 Try this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses typinfo;type  TDays = (mon, tue, weg, thu, fri, sat, sun); var   ThisDay: TDays;  s: string; begin  ThisDay := tue;  s := GetEnumName(TypeInfo(TDays), Ord(ThisDay));  writeln(s);  readln;end. ---------------------------------------------------------------------- Nitorami · 2016-03-22 20:14 Thank you. Given that the writeln () works straightaway, I had expected something simpler and more guessable;  but it does the job. ---------------------------------------------------------------------- eny · 2016-03-22 20:22 Quote from: Nitorami on March 22, 2016, 09:14:12 pmThank you. Given that the writeln () works straightawaywriteln(...) is not a simple procedure but some kind of data displaying wizard that is handled in a special way by the compiler. ---------------------------------------------------------------------- Leledumbo · 2016-03-23 08:07 Quote from: Nitorami on March 22, 2016, 09:14:12 pmThank you. Given that the writeln () works straightaway, I had expected something simpler and more guessable;  but it does the job. WriteStr() and Str() should work on enum. ---------------------------------------------------------------------- Zoran · 2016-03-23 11:34 Quote from: Leledumbo on March 23, 2016, 09:07:02 amQuote from: Nitorami on March 22, 2016, 09:14:12 pmThank you. Given that the writeln () works straightaway, I had expected something simpler and more guessable;  but it does the job. WriteStr() and Str() should work on enum. Yes. Recently I needed this and didn't know how and I found it in some old topic in this forum. I can't find this topic now, but I know where to look in my code and the solution uses WriteStr. This should work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TDays = (mon, tue, weg, thu, fri, sat, sun); var  ThisDay: TDays;  s: string; begin  ThisDay := tue;  WriteStr(S, ThisDay);  writeln(s); // or in GUI LCL project - Label1.Caption := S; or ShowMessage(S); ...  readln;end.  GetMem's solution works same, but this is slightly simpler - you don't need typinfo unit (although I wouldn't be surprised that internally WriteStr calls the same code that GetMem's example does). ---------------------------------------------------------------------- Zoran · 2016-03-23 11:43 Quote from: Zoran on March 23, 2016, 12:34:07 pmI can't find this topic now, Here it is - the post from Cyrax: http://forum.lazarus.freepascal.org/ index.php/topic,30196.msg191770.html#msg191770