A Delphi Set is a combination of binary values that when combined together you can
distinguish which member of the set is contained and which is not
for example:
1 // Code start2 type3 ABC = setof (A, B, C);
4 // Code End5 6 //this gets translated to:7 A = 2^0 {= 1}8 B = 2^1 {= 2}9 C = 2^2 {= 4}
these values can be represented in one byte and combined using (OR) instruction or
checked with (AND) construction (Binary Count), so if you calculate any combination
of them like (A + B = 3) or (A + C = 5) or (B + C = 6) or (A + B + C = 7) you will
find that the possibility of finding a member of the set is either 0 or 1, so you
will never have duplicate member values in the set
This also how it works with Flags parameters in API calls, so whenever you find a
param in an API call that represend multiple combinations of values it is really a
set and here is another example
10 // Code start here11 12 const13 Param2_choice1 = $1;
14 Param2_choice2 = $2;
15 Param2_choice3 = 4;
16 17 procedure SetSomething (Param1: string; Param2 Byte);
18 19 //you can call this function as the following if you want to put the 3 choices:20 21 procedure Something;
22 var23 MyParamSet: integer;
24 begin25 MyParamSet:= Param2_choice1 or Param2_choice3;
26 SetSomething('testing Sets', MyParamSet);
27 end;
28 29 procedure SetSomething (Param1: string; Param2 Byte);
30 begin31 if (Param2 and Param2_choice1) then32 showmessage('choice 1 in param 2');
33 34 if (Param2 and Param2_choice2) then35 showmessage('choice 2 in param 2');
36 37 if (Param2 and Param2_choice3) then38 showmessage('choice 1 in param 3');
39 end;
40 41 // Code end here
I Hope you guys increased your knowledge by this small article and wait for the
following articles with more good subjects :)
And please provide some feedback for me with the Vote so i know what is good for
you and what is bad.
Article written by:
Bishoy Ghaly
Dev2Dev
http://www.dev2dev.org/