Icon Statements

Elevate Web Builder supports most Object Pascal statements, and these statements are detailed below. Please see the Function and Procedure Implementations topic for information on how statements are actually used in function and procedure code blocks.

Assignment Statement
<Variable> := <Type-Compatible Expression>;

The assignment statement uses the assignment operator (:=) to assign a value from a type-compatible expression on right-hand side of the assignment operator to the variable on the left-hand side of the operator.

The following example illustrates the use of the assignment statement:

var
   MyInteger: Integer;
   MyString: String;
begin
   MyInteger := (100 * MyIntegerConstant);
   MyString := 'This is a test';
end;

If Statement
if <Boolean Expression> then
   <Code Block>
[else if <Boolean Expression> then
   <Code Block>]
[else
   <Code Block>];

The if statement is used to provide conditional execution based upon one or more Boolean expressions. When any of the Boolean expressions specified in the if or else if clauses evaluates to True, then the block of statements is executed. The else clause is used to specify that the if none of the Boolean expressions evaluate to True, then the statement block specified for the else clause should be executed.

The following example illustrates the use of the if statement:

var
   MyBoolean: Boolean;
begin
   MyBoolean:=False;
   if MyBoolean then
      ShowMessage('This will never execute')
   else
      ShowMessage('This will always execute');
end;

Case Statement
case <Expression> of
   <Expression>[, <Expression}:
      <Code Block>;
   [<Expression>[, <Expression}:
      <Code Block>;]
   [else
      <Code Block>;]
   end;

The case statement is used to provide conditional execution based upon one or more expression comparisons. The expression directly after the case clause is compared against each expression specified before the colon (:). If any of the expression comparisons are equal, then the block of statements directly after the colon is executed. The else clause is used to specify that if none of the expression comparisons are equal, then the statement block specified for the else clause should be executed.

The following example illustrates the use of the case statement:

var
   MyString: String;
begin
   MyString:='Hello World';
   case MyString of
      'Hello':
         ShowMessage('Hello');
      'World':
         ShowMessage('World');
      else
         ShowMessage('None of the above');
      end;
end;

While Statement
while <Boolean Expression> do
      <Code Block>;

The while statement is used to provide a looping construct based upon a Boolean expression comparison. The Boolean expression directly after the while clause is compared before every execution of the block of statements. If the Boolean expression evaluates to False, then the loop is terminated and execution will continue on the statement after the block of statements that belong to the while statement.

The following example illustrates the use of the while statement:

var
   MyBoolean: Boolean;
begin
   MyBoolean:=True;
   while MyBoolean do
      begin
      ShowMessage('Still looping...');
      if MyBoolean then
         MyBoolean:=False;
      end;
end;

Repeat Statement
repeat
      <Code Block>;
until <Boolean Expression>;

The repeat statement is used to provide a looping construct based upon a Boolean expression comparison. The Boolean expression directly after the util clause is compared after every execution of the block of statements. If the Boolean expression evaluates to True, then the loop is terminated and execution will continue on the statement after the block of statements that belong to the repeat statement.

The following example illustrates the use of the repeat statement:

var
   MyBoolean: Boolean;
begin
   MyBoolean:=False;
   repeat
      begin
      ShowMessage('Still looping...');
      if (not MyBoolean) then
         MyBoolean:=True;
      end;
   until MyBoolean;
end;

For Statement
for <Integer Value Assignment> to|downto <Integer Expression> do
      <Code Block>;

The for statement is used to provide a looping construct based upon an incrementing or decrementing integer value comparison. The loop is seeded with an an integer value assignment that is an assignment statement without a semicolon statement terminator (;). If the to clause is used, then the integer value will be incremented by one for every iteration of the loop, and if the downto clause is used, then the integer value will be decremented by one for every interation of the loop. The integer expression after the to or downto clause serves as the terminator for the loop. Once the integer value is equal to the value of the specified integer expression, the loop is terminated and execution will continue on the statement after the block of statements that belong to the for statement.

The following example illustrates the use of the for statement:

var
   MyInteger: Integer;
   MyString: String='Hello world';
begin
   for MyInteger:=1 to Length(MyString) do
      ShowMessage('Character is '+MyString[MyInteger]+'...');
end;

Break Statement
break;

The break statement is used to unconditionally break out of any looping statement (while, repeat, or for). Any time a break statement is encountered, the loop is terminated and execution will continue on the statement after the block of statements that belong to the looping statement.

The following example illustrates the use of the break statement:

var
   MyInteger: Integer;
   MyString: String='Hello world';
begin
   for MyInteger:=1 to Length(MyString) do
      begin
      ShowMessage('Character is '+MyString[MyInteger]+'...');
      if MyString[MyInteger]='w' then
         break;
      end;
end;

Continue Statement
continue;

The continue statement is used to unconditionally stop executing any and all remaining statements in the block of statements for a looping statement (while, repeat, or for) and return to the top of the looping statement.

The following example illustrates the use of the continue statement:

var
   MyBoolean: Boolean;
begin
   MyBoolean:=True;
   while MyBoolean do
      begin
      ShowMessage('Still looping...forever');
      continue;
      if MyBoolean then
         MyBoolean:=False;
      end;
end;

Exit Statement
exit;

The exit statement is used to unconditionally stop executing any and all remaining statements in a function or procedure, and leave the function or procedure.

With Statement
with <Class Instance> do
   <Code Block>;

The with statement is used to introduce a class instance into the scope of the block of statements specified after the do clause. This is useful when one needs to reference several different properties or methods of the class instance and would like to avoid repeatedly typing the same class instance reference.

The following example illustrates the use of the with statement:

var
   MyInstance: TMyClass;
begin
   MyInstance:=TMyClass.Create;
   with MyInstance do
      begin
      MyIntegerProperty:=100;
      MyStringProperty:='Hello world';
      end;
   MyInstance.Free;
end;

Code Blocks
One or more statements in succession is referred to as a code block. If more than one statement is included in a code block, then the code block must be expressed with the begin and end keywords:

begin
 <Statement>;
 [<Statement>];
end;

For example, the following for loop can be expressed without the begin and end keywords because its code block only consists of a single statement:

var
   MyInteger: Integer;
   MyString: String='Hello world';
   MyOtherString: String='';
begin
   for MyInteger:=1 to Length(MyString) do
      MyOtherString := MyOtherString + MyString[MyInteger];
end;

Code blocks can be nested as many levels deep as necessary.

Statement Termination
One of the most confusing aspects of the Object Pascal language is how to decide when to terminate a statement. Normally, all statements must be terminated with the statement terminator character (;) when the statements are used by themselves. For example, the following assignment statement is terminated in a normal fashion because it is used by itself in a code block:

var
   MyString: String;
begin
   MyString := 'This is a test';
end;

However, when a statement is embedded within another container statement, such as an if statement, the statement terminator may not be needed. For example, the same assignment statement used above would look like this when used in an if statement:

var
   MyString: String;
begin
   if MyParameter then
      MyString := 'This is a test'
   else
      MyString := 'This is not a test';
end;

The first assignment statement does not require a statement terminator because it is considered part of the if statement, whereas the second assignment statement has a statement terminator because it is used in the else clause of the if statement.

The exception to this rule occurs when a statement is used within a code block. Statements always require a statement terminator when used in a code block.
Image