unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, FuncUnit, StdCtrls;type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}uses
TypInfo;function IntegerSet(const mValue; mSize: Word): TIntegerSet;
var
I: Integer;
begin
Result := [];
for I := 0 to mSize - 1 do
Integer(Result) := Integer(Result) + TByteArray(mValue)[I]
end; { IntegerSet }function GetSetStr(mTypeInfo: PTypeInfo; const mValue; mSize: Word;
mBrackets: Boolean = True): string;
var
vCompType: PTypeInfo;
I: Integer;
S: TIntegerSet;
begin
Result := '';
S := IntegerSet(mValue, mSize);
vCompType := GetTypeData(mTypeInfo)^.CompType^;
for I := GetTypeData(vCompType).MinValue to GetTypeData(vCompType).MaxValue do
if I in S then
Result := Result + ',' + GetEnumName(vCompType, I);
Delete(Result, 1, 1);
if mBrackets then Result := '[' + Result + ']';
end; { GetSetStr }function GetSetAll(mTypeInfo: PTypeInfo;
mBrackets: Boolean = True): string;
var
vCompType: PTypeInfo;
I: Integer;
begin
Result := '';
vCompType := GetTypeData(mTypeInfo)^.CompType^;
for I := GetTypeData(vCompType).MinValue to GetTypeData(vCompType).MaxValue do
Result := Result + ',' + GetEnumName(vCompType, I);
Delete(Result, 1, 1);
if mBrackets then Result := '[' + Result + ']';
end; { GetSetAll }type
TMyType = set of (MyType1, MyType2, MyType3, MyType4, MyType5, MyType6);procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Clear;
Memo1.Lines.Add(GetSetStr(TypeInfo(TMyType), [MyType2, MyType5], SizeOf([MyType2, MyType5])));
Memo1.Lines.Add(GetSetAll(TypeInfo(TMyType)));
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, FuncUnit, StdCtrls;type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}uses
TypInfo;function IntegerSet(const mValue; mSize: Word): TIntegerSet;
var
I: Integer;
begin
Result := [];
for I := 0 to mSize - 1 do
Integer(Result) := Integer(Result) + TByteArray(mValue)[I]
end; { IntegerSet }function GetSetStr(mTypeInfo: PTypeInfo; const mValue; mSize: Word;
mBrackets: Boolean = True): string;
var
vCompType: PTypeInfo;
I: Integer;
S: TIntegerSet;
begin
Result := '';
S := IntegerSet(mValue, mSize);
vCompType := GetTypeData(mTypeInfo)^.CompType^;
for I := GetTypeData(vCompType).MinValue to GetTypeData(vCompType).MaxValue do
if I in S then
Result := Result + ',' + GetEnumName(vCompType, I);
Delete(Result, 1, 1);
if mBrackets then Result := '[' + Result + ']';
end; { GetSetStr }function GetSetAll(mTypeInfo: PTypeInfo;
mBrackets: Boolean = True): string;
var
vCompType: PTypeInfo;
I: Integer;
begin
Result := '';
vCompType := GetTypeData(mTypeInfo)^.CompType^;
for I := GetTypeData(vCompType).MinValue to GetTypeData(vCompType).MaxValue do
Result := Result + ',' + GetEnumName(vCompType, I);
Delete(Result, 1, 1);
if mBrackets then Result := '[' + Result + ']';
end; { GetSetAll }type
TMyType = set of (MyType1, MyType2, MyType3, MyType4, MyType5, MyType6);procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Clear;
Memo1.Lines.Add(GetSetStr(TypeInfo(TMyType), [MyType2, MyType5], SizeOf([MyType2, MyType5])));
Memo1.Lines.Add(GetSetAll(TypeInfo(TMyType)));
end;end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货