DelphiBasics
Boolean
Type
Allows just True and False values System unit
type Boolean = (False, True);
Description
The Boolean type provides an enumeration of the logical True and False values.
 
Unlike other languages, it is not a number - it will only allow these values. This makes the code much more reliable.
Notes
Using calculations to test for true or false is a C like practice, but is supported in Delphi. Use the following to hold such a logical number:

ByteBool
WordBool
LongBool

Related commands
AndBoolean and or bitwise and of two arguments
IfStarts a conditional expression to determine what to do next
NotBoolean Not or bitwise not of one arguments
OrBoolean or or bitwise or of two arguments
XorBoolean Xor or bitwise Xor of two arguments
 Download this web site as a Windows program.




 
Example code : Boolean assignments and tests
var
  same : Boolean;
  small, large, i : Integer;

begin
  small := 23;
  large := 455555;

  // Test directly to see if these numbers are the same size
  if small = large
  then ShowMessage('small = large')
  else ShowMessage('small <> large');

  // Use a Boolean to hold and test this outcome
  same := (small = large);
  if same
  then ShowMessage('small = large')
  else ShowMessage('small <> large');

  // Assign a direct logical value to this Boolean
  same := True;
  if same
  then ShowMessage('same is True')
  else ShowMessage('same is False');
end;
Show full unit code
  small <> large
  small <> large
  same is True
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page