在Delphi如何实现类似如下的语法:a := 'id1'
if a in ('id1', 'id2', 'id3') then
...in 可以这样用吗,怎么用?谢谢大家帮个忙

解决方案 »

  1.   

    if (a in ['id1', 'id2', 'id3']) then
      

  2.   

    不可以这样用,in之可以运用在序数和set之间。
      

  3.   

    set 指的是集合吧?那集合是什么语法呢?
      

  4.   

    同意三楼
    如果是这样就ok了var MySet = set of 'a'..'z';MySet := ['a','b','c'];if 'a' in MySet then ...
      

  5.   

    可以的
    a:char;a:=chr(8);
    if not (a in ['a','b','c']) then showmessage('d');
      

  6.   

    建议你看看object pascal的基础书,下面是关于集合的一章集合
     集合是指相同序数类型值的集合。集合中的值没有固定的顺序,同一个值在一个集合中最多出现一次(即集合中的元素互不相同的)。The range of a set type is the power set of a specific ordinal type, called the base type; that is, the possible values of the set type are all the subsets of the base type, including the empty set. The base type can have no more than 256 possible values, and their ordinalities must fall between 0 and 255. Any construction of the form集合类型的范围是指定序数类型的幂集(见当前页中编者注),这里所说的“指定序数类型”叫做集合的基类型(base type)。也就是说,集合类型所有可能的值都是基类型的子集,包括空集。基类型不能含有多余256个可能的值,基类型的序号也必需在0到255之间。任何具有如下形式set of baseType(这里的基类型baseType是一个适当的序数类型),都标识了一个集合类型。由于基类型的尺寸局限,集合类型通常用子界类型来定义。例如,声明type  TSomeInts = 1..250;  TIntSet = set of TSomeInts;创建了一个叫做TintSet的集合类型,集合元素的取值范围是1到250。也可以如下声明,达到相同效果type TIntSet = set of 1..250; 对于上面给出的声明,可以有如下代码:var Set1, Set2: TIntSet;//声明集合变量 ...Set1 := [1, 3, 5, 7, 9];//向集合赋值Set2 := [2, 4, 6, 8, 10]//向集合赋值 也可以在变量声明中直接使用set of ... 结构:var MySet: set of 'a'..'z'; ...MySet := ['a','b','c']; 下面是其他集合类型的范例set of Byteset of (Club, Diamond, Heart, Spade)set of Char; in运算符用于测试集合成员:if 'a' in MySet then ... { 相应的处理 } ; 所有的集合都能保存空集,用 [] 表示(一对方括号)。
      

  7.   

    集合的元素必须是有序类型,string不是有序类型, 所以不能用in
      

  8.   

    type
      myset = (ad,ab,ac);
    procedure TForm2.Button1Click(Sender: TObject);
    var
     aa : myset;
     set1 : set of myset;begin
      aa := ad;
      set1 := [ab,ad] ;
      if aa in set1 then
      showmessage('ok');
    end;
    是不是这个意思!
      

  9.   

    可能 flyforlove(为情飞) 是对的
      

  10.   

    支持if (a in ['id1', 'id2', 'id3']) then
    in是操作集合数据类型的,和vb,c#中的in是有区别的
    delphi中并没有for each .. in ..语法(delphi8之前)
      

  11.   

    a := 'id1'
    if Pos('/id1/'+ 'id2/'+ 'id3/', a) > 0 then
    ...