[next] [previous] [contents]

  9.1.2 RECORD Variants
  Sometimes it is useful to have different record components
  overlay the same record field, in much the same way that
  multiple maps can overlay the same storage. Such an over-
  lay is called a RECORD variant . You use the keywords
  VARIANT and CASE to set up RECORD variants.

  The following example creates a RECORD template for any
  three kinds of boats:
  
EXAMPLE: Click to display example.

  The SELECT...CASE statement allows you to access one of
  several possible RECORD variants in a particular RECORD
  instance. A RECORD component outside the overlaid fields
  usually determines which RECORD variant is being used in
  a particular reference; in this case, the determining RECORD
  component is Type_of_boat . You can use this component in
  the SELECT expression.
  
EXAMPLE: Click to display example.

  The value of the Type_of_boat component determines the
  format of the variant part of the record.

  The following example is a more complex version of the same
  type of procedure. This program prompts for the RECORD
  instance components in each variant. When the user re-
  sponds to the ``Wage Class'' prompt, the program branches
  to one of three CASE blocks depending on the value of Wage_
  class
.
  
EXAMPLE: Click to display example.

  Variant fields can appear anywhere within the RECORD in-
  stance. When you use RECORD variants, you imply that any
  RECORD instance can contain any one of the listed vari-
  ants. Therefore, if each variant requires a different amount
  of space, BASIC uses the case that requires the most storage
  to determine the space allocated for each RECORD instance.