delphi枚举与字符串转换

以下为D自带帮助中的说明,备存怕忘记
uses TypInfo ;
function GetEnumName(TypeInfo: PTypeInfo; Value: Integer): string;
Returns the name of a Delphi enumerated type constant given its value.
Use GetEnumName to convert a Delphi enumerated value into the symbolic name that represents it in code.
TypeInfo is the type information record that describes the enumerated type. You can obtain the type information for a type by calling the TypeInfo function in Delphi or the __delphirtti operator in C++.
Value is the enumerated value, represented as an integer.
GetEnumName returns the string that represents the specified value.

eg.

  GetEnumName(TypeInfo(TParamType), Ord(mParam.ParamType)


--******************************************
function GetEnumValue(TypeInfo: PTypeInfo; const Name: string): Integer;
Returns the value of an enumerated type constant given its string representation.
Use GetEnumValue to convert the string that represents an enumerated value into the corresponding integer that is its implemented value.
TypeInfo is the type information record that describes the enumerated type. You can obtain the type information for a type by calling the TypeInfo function in Delphi or using the __delphirtti operator in C++.
The Name argument should contains a string representation of an enumerated type constant. GetEnumValue uses a case-insensitive match.
GetEnumValue returns the corresponding integer value, or -1 if Name does not match any constant in the supplied TypeInfo.

eg.

    TParamType(GetEnumValue(TypeInfo(TParamType), 'ptInput'))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值