Mega Code Archive

 
Categories / Delphi / Strings
 

Converting enumerated type values into strings

Title: Converting enumerated type values into strings. Question: How to convert font style values into string values? Answer: For converting enumerated type values into string we should use the GetEnumName function from TypInfo unit. Below is example how to perform this action for TFontStyle type and for our custom type: type TOurType = (otFirst, otSecond, otThird, otForth, otFifth, otLast); procedure TForm1.Button1Click(Sender: TObject); var OT: TOurType; FT: TFontStyle; begin // TFontStyle values Memo1.Lines.Add('The TFontStyle values:'); for FT := Low(TFontStyle) to High(TFontStyle) do Memo1.Lines.Add(GetEnumName(TypeInfo(TFontStyle), ord(FT))); // The custom TOurType values Memo1.Lines.Add('The TOurType values:'); for OT := Low(TOurType) to High(TOurType) do Memo1.Lines.Add(GetEnumName(TypeInfo(TOurType), ord(OT))); end;