问题:1,怎么样定义一个初始的空集合?(集合里边将是字符串而不是其它类型)
      2。怎么样添加进去?

解决方案 »

  1.   

    var  
      v:variant;
    begin
      v:=vararraycreate([0,n],varstring);//n是上界值
      v[0]:='  ';
      //以次类推
    end;
      

  2.   

    var
      IntSet:TIntegerSet;  //这里定义了一个集合IntSet,但内容是随即的,既有可能内容是{1,2,4,6,9},也有可能是{2,5,7,10,3},但很少会为空  
    begin
      Include(IntSet,1);  //将1包含进集合IntSet中,这个操作完成以后,集合只有一个元素1
    end;
      

  3.   

    FrameSniper(人类不能不吃饭@手机不能不充电.net):
    我不要整数型的集合,我要字符串呀!
      

  4.   

    var
      CharSet:TSysCharSet;  //道理同上
    begin
      Include(IntSet,Chr(97));  //将字符'a'包含进集合CharSet中,这个操作完成以后,集合只有一个元素'a'
    end;
      

  5.   

    只有整数才能用于集合,别的都不可以.
    添加元素用
    var
      s:set of Integer;
      x:Integer;
    begin
      s:=[1,2,3];
      s:=s+[4,5];
      x:=10; 
      s:=s+[x]; // 单个元素加上方括号就可以了,算是并集运算.
      

  6.   

    HOHO,只有整数才可以用于集合,那偶问你System单元定义的TSysCharSet是啥类型呢?
      

  7.   

    HOHO,只有整数才可以用于集合,那偶问你System单元定义的TSysCharSet是啥类型呢?
      

  8.   

    A set is a collection of values of the same ordinal type. The values have no inherent order, nor is it meaningful for a value to be included twice in a set.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 formset of baseTypewhere baseType is an appropriate ordinal type, identifies a set type.Because of the size limitations for base types, set types are usually defined with subranges. For example, the declarationstype
      TSomeInts = 1..250;
      TIntSet = set of TSomeInts;create a set type called TIntSet whose values are collections of integers in the range from 1 to 250. You could accomplish the same thing withtype TIntSet = set of 1..250;Given this declaration, you can create a sets like this:var Set1, Set2: TIntSet;
     ...
    Set1 := [1, 3, 5, 7, 9];
    Set2 := [2, 4, 6, 8, 10]You can also use the set of ... construction directly in variable declarations:var MySet: set of 'a'..'z';
     ...
    MySet := ['a','b','c'];Other examples of set types includeset of Byte
    set of (Club, Diamond, Heart, Spade)
    set of Char;The in operator tests set membership:if 'a' in MySet then ... { do something } ;Every set type can hold the empty set, denoted by [].
      

  9.   

    PASCAL 语言的集合,实际在内存中 用 1 个二进位 表示 是否 包含 某一个特定的元素
    因此,对于一个特定的集合类型 元素 的总数 必须事先确定Delphi 何时扩充了集合 的定义 ????(我指的是 SET)
      

  10.   

    有序类型可以作为集合的类型。例如 char, integer, byte, boolean 等,另外枚举类型也可以。
      

  11.   

    跑题了,各位,偶上面的TSysCharSet是Delphi自带类型,大家可以去查查另外上面那个朋友说的集合中只可以为整数的说发是错误的!难道你们平时不定义以枚举为基本类型的集合类型吗?
      

  12.   

    Unit
    SysUtilstype TSysCharSet = set of Char;其实是 Char Set,而 string 是不可以作为 set 集合元素的
      

  13.   

    HOHO,我说的整数类型就是 Ordinal types,在内存中以整数格式保存的,包括Char,AnsiChar,WideChar,枚举,...
    本人的习惯说法给大家带来误解了,道歉先.
      

  14.   

    大哥们:
    都不行,你们的建议对单个字符行,也就是:['a','b','z',....]
    但对:['aaa','bbb','ccc',....]不行
      

  15.   

    如果字符串不能为集合,那怎么样判断一个字符串变量的值属于一些字符串集呢?
    stringlist?
    Tcollection?
      

  16.   

    TStringList,它有 find 等方法来判断一个字符串是否在其中
      

  17.   

    集合元素必须是有序类型!使用TStringList类对象
      

  18.   

    我原来想判断一个字段name的值是否在这个集合中,现在用stringlist,这个where怎么写?
    select * from table where name in ['aaa','bbb','ccc']
      

  19.   

    必须转换成 SQL 语法啊!
    就算Delphi 有这个字符串集合,也不能就直接用啊
      

  20.   

    我这人就是对sql语句不适应。
      

  21.   

    我发现象这种select也出错
    select * from table where copy(name,1,1)='m' 
    为什么?
    这种都出错,这种select有什么用?
      

  22.   

    select * from table where mid(name,1,1)='m'
      

  23.   

    select * from table where name in ('aaa','bbb','ccc')