>  x := [chris, pam, mary]; sets bits 1,4,6 *not packed* in x.
>  y := [chris]                       sets bit 1 in y

That should be bits 0,3,5 (enumeration ords are zero based) but otherwise right
 
> which is why union operators are fast as they are single Op Codes
> Ord(x) = 1 + 8 + 32 = 41
> Ord(y)  = 1

You can't get the Ord of a set... this is incorrect...

in the code
type
   MySet = (chris, john, bob, mary, fred, pam);
   MyXSet =  set of MySet;
var
  S :MyXSet;
  I :Integer;
begin
  S := [chris, john, bob];
  I := ord(S);
end;

the compiler stops on ord(S) with error incompatible types...
You can get the Ord of an enumeration element not a set. You can however cast
a set to an integer for all enumerations <= 32 elements (with a little fiddling).

type
  MySet = (chris, john, bob, mary, fred, pam);
  MyXSet =  set of MySet;
var
  M :Myset;
  S :MyXSet;
  I :Integer;
  P :Pointer;
begin
  M := pam; // M is 5, the compiler symbol table enforces type-safety but it's just a 5
  I := Integer(M); // I is 5;
  I := ord(M); // I is 5;

  S := [pam,john,mary,bob];

  for M := low(M) to High(M) do if M in S then
    ShowMessage(intToStr(ord(M))); // This will show john,bob,mary,pam in this order.

  P := @S;
  I := Integer(P^) and ((2 shl Ord(High(Myset)))-1); // this should be 2+4+8+32 = 46;
end;

--
Aaron Scott-Boddendijk
Jump Productions
(07) 838-3371 Voice
(07) 838-3372 Fax


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to