Part of an if statement - starts the true clause
1   if Condition then Statement;
2   if Condition then Statement else Statement;
The Then keyword is part of the If statement. It is used to start the section of code executed when the if condition is true.
There are two forms of the If statement - one with an else clause, the other not.
If works as follows :
If the condition is true, then the first statement is executed. If false, then this statement is bypassed. If there is an else statement, it is executed instead.
In all cases, the Statement clause must be contained in a begin/end block if it is longer than one statement in length.
It is an easy mistake to make, but Delphi insists on no ; after the then statement if an else statement follows.
Related commands
Else Starts false section of if, case and try statements
End Keyword that terminates statement blocks
If Starts a conditional expression to determine what to do next
 Author links

 Buy Website Traffic at

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

Example code : Illustrate various uses of the then clause
// 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;
  Forms, Dialogs;
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
Form1: TForm1;
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);

  // Illustrate a simple if statement that executes true
  if True Then ShowMessage('True!');

  // Illustrate the same, but with multiple actions
  if 1 = 1 Then
    ShowMessage('We now have');
    ShowMessage('multiple lines');

  // Illustrate a simple if statement that fails
  if 1 = 2 Then ShowMessage('1 = 2');

  // Illustrate an if then else statement
  // Note the lack of a ';' after the 'then' clause
  if False
  Then ShowMessage('True')
  else ShowMessage('False');

  // Nested if statements - Delphi sensibly manages associations
  if true Then
    if false Then
      ShowMessage('Inner then satisfied')
      ShowMessage('Inner else satisfied')
    ShowMessage('Outer else satisfied')
Hide full unit code
   We now have
   multiple lines
   Inner else satisfied
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page