集合型の演算
|
84 |
TypeSetOfPlusMinus |
動作確認 |
Delphi2007 |
更新日 |
2008/02/20(水) |
集合型の演算方法です。
例えば、フォントスタイル、太字/斜体/取消線/下線だと
定義は
TFontStyle = (fsBold, fsItalic, fsUnderline, fsStrikeOut);
TFontStyles = set of TFontStyle;
このようになっています。
各要素が含まれているかどうかを判断するのは in 演算子を使い
追加したり取り除いたりするには + - 演算子を使います。
────────────────────
procedure TForm1.Button1Click(Sender: TObject);
begin
if fsBold in Label1.Font.Style then
begin
Label1.Font.Style := Label1.Font.Style - [fsBold, fsItalic];
end else
begin
Label1.Font.Style := Label1.Font.Style + [fsBold, fsItalic];
end;
end;
────────────────────
また、集合型のプロパティには使えないのですが
集合型の変数に対してはInclude/Excludeという命令も使えます。
Includeが含ませる
Excludeは取り除くです。
下記を参考にしてみてください。
────────────────────
procedure TForm1.Button2Click(Sender: TObject);
var
FontStyle: TFontStyles;
begin
if fsUnderline in Label1.Font.Style then
begin
FontStyle := Label1.Font.Style;
Exclude(FontStyle, fsStrikeOut);
Exclude(FontStyle, fsUnderline);
Label1.Font.Style := FontStyle;
end else
begin
FontStyle := Label1.Font.Style;
Include(FontStyle, fsStrikeOut);
Include(FontStyle, fsUnderline);
Label1.Font.Style := FontStyle;
end;
end;
────────────────────
集合型プロパティに使えないのは残念です。
|