比如:
var
 MyStr:Set of 'a'..'z';
begin
 MyStr:=['a'..'z'];
 Edit1.Text:=MyStr;//执行到这一句时,提示:Incompatible types: 'String' and 'Set'
end;直接赋值不行,怎样做才能在Edit中显示集合类型的内容呢?

解决方案 »

  1.   

    var
     MyStr:Set of 'a'..'z';
     C : Char;
    begin
     MyStr:=['a'..'d','f','z'];
     Edit1.Text := '';
     for C := 'a' to 'z' do
       if C in MyStr then
          Edit1.Text:= Edit1.Text + C;
    end;
      

  2.   

    集合是一块32个字节的内存,共256个二进制位,每个位的值0或1代表相对应的序数元素的无或有。(请参阅我的一篇文章:http://community.csdn.net/Expert/TopicView.asp?id=5337219)类似你的需求,你应该试用一下字符数组。
      

  3.   

    var
     MyStr:Set of 'a'..'z';
     A:Char;
     Str:string;
    begin
      MyStr:=['a'..'z'];
      for A:='a' to 'z' do
        if A in MyStr then
           Str:=Str+A;
      Edit1.Text:=Str;
    end;
      

  4.   

    // 集合中可以是字符类型,整型或枚举等等。直接当string用当然是不行的。
    // 不同的集合要用不同的方法显示。给你个具体的例子:function EnumName(Value: LongInt; Info: PTypeInfo): string;
    var
      Data: PTypeData;
    begin
      Data := GetTypeData(Info);
      if (Value < Data^.MinValue) or (Value > Data^.MaxValue) then Value := Data^.MinValue;
      Result := GetEnumName(Info, Value);
    end;function SetToString(const SetValue; Info: PTypeInfo): string;
    var
      MaskValue,I: LongInt;
      Data,CompData: PTypeData;
      CompInfo: PTypeInfo;
    begin
      Data := GetTypeData(Info);
      CompInfo := Data^.CompType^;
      CompData := GetTypeData(CompInfo);
      MaskValue := LongInt(SetValue);
      Result := '[';
      for I := CompData^.MinValue to CompData^.MaxValue do
      begin
        if (MaskValue and 1) <> 0 then AppendStr(Result, EnumName(I, CompInfo) + ',');
        MaskValue := MaskValue shr 1;
      end;
      if Result[Length(Result)] = ',' then
        Delete(Result, Length(Result), 1);
      AppendStr(Result, ']');
    end;type
      TMyColor = (Red, Green, Blue);
      TMyColors = set of TMyColor;procedure TForm1.Button1Click(Sender: TObject);
    var
      Colors : TMyColors;
    begin
      Colors := [Red, Blue];
      Edit1.Text := SetToString(Colors, TypeInfo(TMyColors));
    end;
      

  5.   

    TO 楼上:  “集合中可以是字符类型,整型或枚举等等。直接当string用当然是不行的。”----------------------------------------1、集合不可以是整型的。你可以试一下。 var ISet : set of integer;2、枚举是集合类型的一个特例,因此,枚举也是集合。3、无论你的集合表示为什么样子的,其实它就是一块256位的内存。