首先引用TypInfo单元
type
TCommandEnum = (_AA, _BB, _CC, _DD, _EE, _FF, _GG, _HH);
procedure TCommandProcess.ProcessCmd(chn: Byte; cmd, s: string);
var
CMDEnum:TcommandEnum ;
begin
CMDEnum :=TCommandEnum(GetEnumvalue(TypeInfo(TCommandEnum), '_'+cmd));
case CMDEnum of
_AA: ProcessAA(chn, s);
_BB: ProcessBB(chn, s);
_CC: ProcessCC(chn, s);
_DD: ProcessDD(chn, s);
_EE: ProcessEE(chn, s);
_FF: ProcessFF(chn, s);
_GG: ProcessGG(chn, s);
_HH: ProcessHH(chn, s);
end;
end;
使用上面的方法可以提高程序的可读性