qp.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
Subrange Types
  Ordinal Types Contents Index                              Back
 
  TYPE
        <identifier> = <first value> .. <last value>;
 
  Description
 
    A subrange type is a subset of any existing ordinal type. The
    existing ordinal type is called the subrange's base type.
    Subranges and their values have the following characteristics:
 
      ■ <first value> and <last value> are both members of the base
        type.
      ■ <first value> <= <last value>
 
    Subrange types are useful for catching errors of magnitude. For
    instance, if an age greater than 120 is entered when the following
    program prompts for an age, a run-time error occurs:
 
       TYPE
           age = 0 .. 120;
 
       VAR
           accept_age : age;
 
       BEGIN
           Write( 'Enter your age: ' );
           {$R+}Readln( accept_age );{$R-}
       END.
 
    Note the use of the Range Checking directive ({$R+} and {$R-}).
    The run-time system will not catch a range error unless the Range
    Checking directive is either explicitly used within a program, or
    set with the Options menu.