Delphi Basics
Do
Keyword
Defines the start of some controlled action
  1. for   Variable := Expression to Expression do Statement;
  2. while Expression do Statement
  3. try   Statements except on ExceptionClass do Statement; end;
  4. with  Expression do Statement
Description
The Do keyword is always a part of one of the shown 4 control types. It precedes the Statements section of the control action.
Related commands
Begin Keyword that starts a statement block
End Keyword that terminates statement blocks
Except Starts the error trapping clause of a Try statement
For Starts a loop that executes a finite number of times
Repeat Repeat statements until a ternmination condition is met
Try Starts code that has error trapping
While Repeat statements whilst a continuation condition is met
With A means of simplifying references to structured variables
 
Example code : Show singles and block do statement blocks
// 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;
 
interface
 
uses
  SysUtils,
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

var
  i : Integer;

begin
  // A for statement - the do keyword precedes a single statement
  for i := 1 to 3 Do
    ShowMessage('For loop, i = '+IntToStr(i));

  // A while statement - the do precedes a statement block
  while i < 6 Do
  begin
    ShowMessage('While loop, i = '+IntToStr(i));
    Inc(i);
  end;
end;
 
end.
Hide full unit code
   For loop, i = 1
   For loop, i = 2
   For loop, i = 3
   While loop, i = 4
   While loop, i = 5
 
 
© CodeGear 2006 - 2007. All rights reserved.  |  Home Page