Delphi 枚举转字符串
原创
©著作权归作者所有:来自51CTO博客作者暖流中的鱼的原创作品,请联系作者获取转载授权,否则将追究法律责任
implementation Uses TypInfo;
procedure TForm3.FormCreate(Sender: TObject);
//定义枚举类型
type
TDayOfWeek=(Monday,Tuesday,Wednesday,Thursday,FriDay,Saturday,Sunday);
var
s: string;
aWeek:TDayOfWeek;
begin
ShowMessage('枚举字符串:' + GetEnumName(TypeInfo(TDayOfWeek), 0) );
ShowMessage('枚举字符串:' + GetEnumName(TypeInfo(TDayOfWeek),Ord(Monday)));
aWeek:=Monday;
ShowMessage('枚举字符串:' + GetEnumName(TypeInfo(TDayOfWeek),Ord(aWeek)));
end;
GetEnumName(TypeInfo( System.TTypeKind), ord( pMethod.ReturnType.TypeKind));