Sign in Join
Wiki copytemporary

subrange types

Deutsch · English · Français

Back to data types.

Range of values: Corresponds to the definition defined by yourself

Storage requirements: Corresponds to the underlying basic data type

A subrange type:

Assigning other values ​​leads to compiler error messages when the program is compiled and the compilation process is aborted. That is, the executable program is not created.

There are two ways to define subrange types.

Variant 1:

pascal
var
  // Defines an integer subrange type
  // in the range of 10 to 123
  tbNumber1 : 10 .. 123;

  // Defines a character subrange type
  // in the range of A to Z (all uppercase)
  tbLetter1 : 'A' .. 'Z';

Variant 2:

pascal
Type
  // Defines an integer subrange type
  // in the range of 10 to 123
  TNumber2 = 10 .. 123;

  // Defines a character subrange type
  // in the range of A to Z (all uppercase)
  TLetter2 = 'A' .. 'Z';

var
  tbNumber2 : TNumber2 ;
  tbLetter2 : TLetter2 ;

Examples of assigning valid values:

pascal
  tbNumber1 := 10;
  tbNumber1 := 123;
  tbNumber2 := 10;
  tbNumber2 := 123;
  tbLetter1 := 'F';
  tbLetter2 := 'F';

Examples of assigning invalid values:

pascal
  // the values are outside the subrange
  tbNumber1 := 9;
  tbNumber2 := 124;
  tbLetter1 := 'f';
  tbLetter2 := 'f';
  // the values ​​are string literals
  tbNumber1 := '10';
  tbNumber1 := '123';
  tbNumber2 := '10';
  tbNumber2 := '123';

From the Free Pascal wiki, page "subrange types", as it stood on 2020-03-01 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.