Title: Enumerated set to Int64
Question: A cast like Int64(EnumSet) doesn't work on sets, so here is a function to transform any Enumerated set in Int64 type.
Answer:
uses System, TypInfo;
function EnumValuesToInt64(PEnumSet: PTypeInfo; AValue: Pointer): Int64;
var
btSize : Byte;
begin
Result := 0;
btSize := SizeOf(PEnumSet);
if (btSize = 0) or (btSize SizeOf(Result)) then
Exit;
Move(AValue^, Result, btSize);
end;
How to use it
-------------
type
TAnyEnumerated = (aeFirst, aeSecond, aeThird, aeFourth);
TEnumeratedSets = set of TAnyEnumerated;
...
var
EnumSets: TEnumeratedSets;
EnumValue: Int64;
begin
EnumSets := [aeSecond, aeFourth];
EnumValue := EnumValuesToInt64(TypeInfo(TEnumeratedSets), @EnumSets);
// EnumValue -- 10
end;
...