Description |
The In keyword tests whether a value is in a set. It returns true if it is, false if not.
|
|
Notes |
Sets are limited to 256 different values. Each element is equated with the Integer values 0,1,2 ... 255
Integer sets map directly to these element values, and are therefore limited to a high value of 255.
However, you may compare a value greater than 255 with an Integer set. Delphi simply uses the lowest byte of the Integer. For example, a test value of 258 would have a lower byte value of 3.
|
|
Related commands |
Exclude |
|
Exclude a value in a set variable |
Include |
|
Include a value in a set variable |
Set |
|
Defines a set of up to 255 distinct values |
|
|
|
Example code : Determine whether a character is a letter |
// 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 Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure IsLetter(Letter : char);
end; var Form1: TForm1; implementation {$R *.dfm} // Include form definitions procedure TForm1.FormCreate(Sender: TObject); begin IsLetter('G'); // G is a letter of the (uppercase) alphabet IsLetter('1'); // 1 is not a letter
end;
// Test if a character is a letter
procedure TForm1.IsLetter(Letter : char);
var
Alphabet : set of 'A'..'Z';
begin
Alphabet := ['A'..'Z'];
if Letter In Alphabet then
ShowMessage(Letter+' is in the alphabet')
else
ShowMessage(Letter+' is NOT in the alphabet');
end; end.
|
Hide full unit code |
G is in the alphabet
1 is NOT in the alphabet
|
|