Contents | Prev | Next

9.12 With statement

Description

With statements perform an action, while allowing the fields of specified record variables to be referencing using their field identifiers only. With statements include the following:

Example

For example give the following type and variable.

   type
     student = record
     name : string;
     address : string;
     grade : integer;
     end;

   var
     s : student;

then the following with statement

   with s do
      begin
         name := 'John';
         address := 'main street';
         grade := 20;
      end

is equivalent to

   begin
      s.name := 'John';
      s.address := 'main street';
      s.grade := 20;
   end

Since some record types can contain other record types you can have nested with statements like the following:

   with record1 do
      with record2 do
        with record3 do
           statement

or you can use the following shorthand which does the same thing

  with record1, record2, record3 do
     statement

Syntax

(NOTE: for clarity some parts of the syntax are omitted, see Irie Pascal Grammar for the full syntax):

   with-statement = 'with' record-variable-list 'do' statement

   record-variable-list = record-variable { ';' record-variable }

Contents | Prev | Next