Keyword that starts a statement block
 keyword Begin(begin
The Begin keyword is fundamental to Delphi - it starts statement blocks.
The begin-end pair fence in a set of statements. You may place such a block anywhere in your code.
It is particularly sensible in if and for statements, even if only one statement is required. It means that adding an additional statement in the future is easy.
For example :
if a = 7 then do
  Inc(b, a);

Is better written :
if a = 7 then do
  Inc(b, a);

for maintenance purposes.
Related commands
EndKeyword that terminates statement blocks
ForStarts a loop that executes a finite number of times
FunctionDefines a subroutine that returns a value
ProcedureDefines a subroutine that does not return a value
RepeatRepeat statements until a ternmination condition is met
WhileRepeat statements whilst a continuation condition is met
 Download this web site as a Windows program.

Example code : Some examples of the begin statement
  myChars : array[1..2] of char;
  myBytes : array[1..2] of Byte;
  i : Integer;

// The begin statement always starts the code part of a subroutine
  // Use a for block to assign to both arrays
  for i := 1 to 2 do
    myChars[i] := Chr(i+64);
    myBytes[i] := i+64;

  // Use a for block to observe the contents
  for i := 1 to 2 do
    ShowMessage('myChars['+IntToStr(i)+'] = '+myChars[i]);
    ShowMessage('myBytes['+IntToStr(i)+'] = '+IntToStr(myBytes[i]));
Show full unit code
  myChars[1] = A
  myBytes[1] = 65
  myChars[2] = B
  myChars[2] = 66
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page