集合型は便利だ。すごく便利だ。しかし、涙を飲んで定数にする場合がある。
なぜなら、集合型はファイルに保存したりするときに、数値や文字列に
変換するのが面倒だからだ。そこで、汎用型変換ルーチンを作った。
役だてていただきたい。

type TYPE = (...)
type TYPES = set of TYPE; 
↑と宣言している集合型と整数の相互変換ルーチン

{ 集合型を整数に変換..64要素まで対応 }
function TYPES2Int(S:TYPES):Int64
var
 I:TYPE;
begin
 if Ord(High(TYPE)) >= 64 then
  raise Exception.Create('要素数が多すぎる');
 for I := Low(TYPE) to High(TYPE) do
  if I in S then
   Inc( Result, 1 shl Ord(I) );
end;

{ 整数を集合型に変換..64要素まで対応 }
function Int2TYPES(S:Int64):TYPES;
var
 I:Integer;
begin
 if Ord(High(TYPE)) >= 64 then
  raise Exception.Create('要素数が多すぎる');
 for I := Low(TYPE) to High(TYPE) do
  if S and (1 shl Ord(I)) <> 0 then
   Include( Result, I );
end;