type Date is record Day : Integer range 1 .. 31; Month : Integer range 1 .. 12; Year : Integer range 1 .. 4000 := 1995; end record;
The record component `Year' has an example of an `initialization clause' - any object created with this type automatically has initial values given in initialization clauses.
Creating variables of a record type is done the same way as any other type. A record component is referenced by using the variable name, a period, and the name of the record component. For example, let's create a variable called Ada_Birthday, and set its values to December 10, 1815:
procedure Demo_Date is Ada_Birthday : Date; begin Ada_Birthday.Month := 12; Ada_Birthday.Day := 10; Ada_Birthday.Year := 1815; end Demo_Date;
If you had the following record type:
type Complex is record Real_Part, Imaginary_Part : Float := 0.0; end record;
and you declared the following type:
X : Complex;
How would you set X's Real_Part to 1?
![]() |
![]() |
![]() |
---|
David A. Wheeler (dwheeler@ida.org)
The master copy of this file is at "http://www.adahome.com/Tutorials/Lovelace/s6s6.htm".