Keyword that starts a statement block
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
End Keyword that terminates statement blocks
For Starts a loop that executes a finite number of times
Function Defines a subroutine that returns a value
Procedure Defines a subroutine that does not return a value
Repeat Repeat statements until a ternmination condition is met
While Repeat statements whilst a continuation condition is met
 Author links

 Buy Website Traffic at

 Buy Proxies at
 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 2002 - 2016. All rights reserved.  |  Home Page