Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Delphi Sets {Behind the scene} Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
18-Oct-04
Category
Object Pascal
Language
Delphi All Versions
Views
538
User Rating
9
# Votes
1
Replies
0
Publisher:
Ghaly, Bishoy
Reference URL:
			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 start
2   type
3     ABC = set of (A, B, C);
4   // Code End
5   
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 here
11  
12  const
13    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  var
23    MyParamSet: integer;
24  begin
25    MyParamSet:= Param2_choice1 or Param2_choice3;
26    SetSomething('testing Sets', MyParamSet);
27  end;
28  
29  procedure SetSomething (Param1: string; Param2 Byte);
30  begin
31    if (Param2 and Param2_choice1) then
32      showmessage('choice 1 in param 2');
33  
34    if (Param2 and Param2_choice2) then
35      showmessage('choice 2 in param 2');
36  
37    if (Param2 and Param2_choice3) then
38      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/

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC