Home  |  Delphi .net Home  |  System.Enum  |  GetName Method
  
GetName  
Method  
Gets the name of a specified enumeration value
Enum Class
System NameSpace
NotCF1.  Function GetName ( EnumeratedType : Type; Value : Object ) : String; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
Attempts to return the Value name for the given EnumeratedType.
 
An enumeration is essentially a set of named constants. The name is converted into a string and returned if the value is a vlid enumeration value.
Notes
If the Value is a set of enum flags (where the enum has the [FalgsAttribute]), then GetName does not resolve the name, and returns an empty string.
Microsoft MSDN Links
System
System.Enum
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
Showing single enum and flagged enum values
program Project1;
{$APPTYPE CONSOLE}

type
  // An enum treated as a set
  [FlagsAttribute]
  Qualities  = (Sexy = 1, Clever = 2, Handsome = 4);

var
  Brian  : System.Enum;
  Jim    : System.Enum;

  Result : String;

begin
  // Using a single enum value
  Brian  := Sexy;
  Result := System.Enum.GetName(TypeOf(Qualities), Brian);
  Console.WriteLine('Brian is ' + Result);

  // Using a multiple enum value (flags)
  Jim    := Sexy or Clever;
  Result := System.Enum.GetName(TypeOf(Qualities),  Jim);
  Console.WriteLine('Jim   is ' + Result);
  Console.WriteLine('Cannot resolve the name since it is ambiguous');

  Console.ReadLine;
end.
   Brian is Sexy
   Jim   is
   Cannot resolve the name since it is ambiguous
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author