集合和字符串互转
集合:
type
TSocketState = (ssDisconnecting, ssDisconnected, ssConnected, ssConnecting, ssListening, ssAccepting);
const
TSocketStateCaption: array[TSocketState] of String = ('正在断开', '已经断开', '已经连接', '正在连接', '正在侦听', '正在接入');
type
TCommandType = (ctEmptyCommand, ctAdd, ctModify); TCommandTypeConvert = class
public
class function CommandToString(ACommand: TCommandType): string;
class function StringToCommand(const AStrCommand: string): TCommandType;
end; implementation class function TCommandTypeConvert.CommandToString
(ACommand: TCommandType): string;
begin
Result := GetEnumName(TypeInfo(TCommandType), Ord(ACommand));
end; class function TCommandTypeConvert.StringToCommand(const AStrCommand: string)
: TCommandType;
begin
Result := TCommandType(GetEnumValue(TypeInfo(TCommandType), AStrCommand));
end;
调用方法:
str:=GetEnumName(TypeInfo(TSocketState),Ord(lvClient.SocketState));