About the author
Sets and enumerations have been in Delphi since the beginning of Delphi.
Here's an example program. The example program gives the exact output in both Delphi 7 and Delphi 8.
However, if you are using sets or enumerations to talk to other .NET programs, you should be aware that there are some differences that were not documented.
In particular, in Delphi, whatever the value of an enumeration, when it becomes part of a set, the value of an enumeration in the set itself is multiplied by 2.
The differences become fundamental, when you examine how it works in C#, and how it works in Delphi, and you want to talk to a CLR routine using Delphi.
More on that in part 2 of this article. In the meantime, can you figure out the output of the following program?
program SetExamples; {$APPTYPE CONSOLE} uses SysUtils; type ASet = (A1=1, A2=2, A3=4, A4=8, A5=16); ASets = set of ASet; var Set1: ASet; Sets: ASets; begin Set1 := A1; Sets := [Set1]; if A1 in Sets then WriteLn('A1'); if A1 = Set1 then WriteLn('Passed'); WriteLn('Set1 value: ', Ord(Set1)); WriteLn('Sets value: ', Integer(Sets)); end.
How to free more space on your home drive by redirecting the location for SDKs in RAD Studio
Learn the command line used to compile System.pas in Delphi
A method to design records so that they're allocated on a specific byte boundary, such as 16 bytes, 512 bytes, 4096 bytes, etc.
Learn why the map is cool in Go!