比如:
var
MyStr:Set of 'a'..'z';
begin
MyStr:=['a'..'z'];
Edit1.Text:=MyStr;//执行到这一句时,提示:Incompatible types: 'String' and 'Set'
end;直接赋值不行,怎样做才能在Edit中显示集合类型的内容呢?
var
MyStr:Set of 'a'..'z';
begin
MyStr:=['a'..'z'];
Edit1.Text:=MyStr;//执行到这一句时,提示:Incompatible types: 'String' and 'Set'
end;直接赋值不行,怎样做才能在Edit中显示集合类型的内容呢?
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;
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;
// 不同的集合要用不同的方法显示。给你个具体的例子: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;