function GetSetName(const aSet:PTypeInfo; Value: Integer):string;
var
vData1 : PTypeData;
vData2 : PTypeData;
vCntr : Integer;
v: Integer;
begin
Result := '';
if aSet^.Kind = tkSet then begin
vData1 := GetTypeData(aSet);
vData2 := GetTypeData(vData1^.CompType);
for vCntr := vData2^.MinValue to vData2^.MaxValue do
if (Value shr vCntr) and 1 <> 0 then
Result := Result+ GetEnumName(vData1^.CompType,vCntr)+',';
if Result <> '' then Delete(Result, Length(Result), 1);
end;
end;
function GetSetValue(const aSet:PTypeInfo; Name: String): Integer;
var
vData1 : PTypeData;
vData2 : PTypeData;
vCntr : Integer;
p : Integer;
begin
Result := 0;
if aSet^.Kind = tkSet then begin
vData1 := GetTypeData(aSet);
vData2 := GetTypeData(vData1^.CompType);
for vCntr := vData2^.MinValue to vData2^.MaxValue do begin
p := pos(GetEnumName(vData1^.CompType, vCntr), Name);
if p = 0 then
Continue;
if (p = 1) or (Name[p-1] = ',') then
Result := Result or (1 shl vCntr);
end;
end;
end;
{ TForm1 }
procedure TForm1.CbBoldClick(Sender: TObject);
var
fs: TFontStyles;
s: String;
begin
fs := [];
if CbBold.Checked then begin
Memo1.Lines.Add('Bold: yes');
Include(fs, fsBold);
end else
Memo1.Lines.Add('Bold: -');
if CbItalic.Checked then begin
Memo1.Lines.Add('Italic: yes');
Include(fs, fsItalic);
end else
Memo1.Lines.Add('Italic: -');
if CbUnderline.Checked then begin
Memo1.Lines.Add('Underline: yes');
Include(fs, fsUnderline);
end else
Memo1.Lines.Add('Underline: -');
if CbStrikeout.Checked then begin
Memo1.Lines.Add('Strikeout: yes');
Include(fs, fsStrikeOut);
end else
Memo1.Lines.Add('Strikeout: -');
s := GetSetName(TypeInfo(TFontStyles), integer(fs));
Memo1.Lines.Add('GetSetName: ' + s);
Memo1.Lines.Add('GetSetValue: ' + IntToStr(GetSetValue(TypeInfo(TFontStyles), s)));
Memo1.Lines.Add('-----------------------------------------------------');
Memo1.Lines.Add('');
end;