DelphiBasics
Include
Procedure
Include a value in a set variable System unit
 procedure Include ( var SetVariable : set of SetValues; OneOfSet : SetValues ) ;
Description
The Include procedure includes a set value in a set variable.
 
A set variable is one that can contain 0, some, or all values of a set. When you Include a set value in a set variable, you are adding to the included values in the variable.
 
Include is equivalent to the + operator, as shown here :
 
Include(CardHand, JackOfClubs);
CardHand := CardHand + [JackOfClubs];

 
For example, you can insert a playing card into a players hand - where the hand is based on a set of all playing cards in a deck.
 
Use Exclude to remove a value from a set variable. This would, for example, allow a card to be removed from a player's hand.
Related commands
Exclude Exclude a value in a set variable
In Used to test if a value is a member of a set
Set Defines a set of up to 255 distinct values
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 Download this web site as a Windows program.




 
Example code : Creating a variable containing only positive numbers 0 to 10
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  // The System unit does not need to be defined
  SysUtils,
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

var
  evenNumbers : Set of 0..10;
  i : Integer;
begin
  // Make sure that evenNumbers only contains even numbers
  evenNumbers := [];
  for i := 0 to 10 do
    if (i mod 2) = 0
    then Include(evenNumbers, i);

  // Now display the set contents
  for i := 0 to 10 do
    if i in evenNumbers
    then ShowMessage(IntToStr(i)+' is even');
end;
 
end.
Hide full unit code
   0 is even
   2 is even
   4 is even
   6 is even
   8 is even
   10 is even
  
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page