Ada 95 has the ability to access a local or global variable with an access variable. This was not permitted with Ada 83. In order to do so, it is necessary to identify the access variable as one with the ability to access a local or global variable by using the keyword all as is done in lines 13 through 15 of the example program.
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;
procedure AcessAll is
type BRICK_TYPE is record
Length : INTEGER;
Width : INTEGER;
Height : INTEGER;
end record;
type ACCESS_INT is access all INTEGER;
type ACCESS_FLT is access all FLOAT;
type ACCESS_BRICK is access all BRICK_TYPE;
Number : INTEGER :=27;
Count : aliased INTEGER :=12;
Pt_Count : ACCESS_INT;
Size : aliased FLOAT :=7.4;
Pt_Size : ACCESS_FLT;
Brick : aliased BRICK_TYPE :=(3,4,6);
Pt_Brick : ACCESS_BRICK;
begin
Pt_Count := Count'Access;-- Pt_Count := Number'Access; Illegal - Number not aliased
-- Pt_Count := Size'Access; Illegal - Size is FLOAT
-- Pt_Count := Brick'Access; Illegal - Brick is BRICK_TYPE
Pt_Count.All := Pt_Count.All +13;Put("The value of Count is now ");Put(Count,5);
New_Line;
Pt_Size := Size'Access;Put("The value of Size is now ");Put(Pt_Size.All,5,2,0);
New_Line;
Pt_Brick := Brick'Access;Put("The brick measures ");Put(Pt_Brick.Length,5);-- Using the pointer
Put(Pt_Brick.Width,5);-- Using the pointer
Put(Brick.Height,5);-- Using the object
New_Line;
end AcessAll;