type TMyMJ=('aa','bb','cc','dd');
var
  s1:string;  s1:='bb';如何判断s1在不在TMyMJ中,并得到它在类型声明是的位置?

解决方案 »

  1.   

    use typinfo;
    好象是GetEnumValue之类的
      

  2.   

    type
      ttest = (aaa, bbb, ccc);
    枚举类型定义是用标识符,不是”字符串”,而且不能超过255个。typinfo.pasAname = GetEnumName(TypeInfo(Ttest), 0); /// 返回 'aaa'
      

  3.   

    用ord()
    如:
    type test=(aaa, bbb, ccc);ord(bbb)=1;//序号从零开始
      

  4.   

    var
      i:integer;
      s:string;
      a:Colors;
     begin
       s:='bb';
       a:=low(colors);
       i:=1;
       while a<>high(colors) do
       begin
         if s=(GetEnumName(TypeInfo(Colors),i-1))   then
         begin
           showmessage('存在');
         end ;
         i:=i+1;
         a:=succ(a);
       end;
       showmessage(inttostr(i));
     end;