Previous topic | Next topic | Ada Home Page | Index

Using Packages

To use the elements of a package, you need to import the package into the program, so that its elements are available for use. You also need to know how to refer to an element in order to use it.

Importing Packages

WITH makes package contents available

        package PLANE is         -- specification
           ...
        end PLANE;



        with TEXT_IO, PLANE;     -- user program
        procedure lab6 is
           ...
        end lab6;



        with TEXT_IO;            -- body
        package body PLANE is
           ...
        end PLANE;

Using Packages

to use a package element:

	package.element

example:

	TEXT_IO.PUT ("abc");
	TEXT_IO.NEW_LINE;
	int_io.PUT (mark, width => 1);
        PLANIMETRY.area_circle (2.0);
        PLANE.get_coordinates (X1,Y1);

USE (in declarations) allows package name to be omitted

	use TEXT_IO,int_io;
	...
	PUT ("abc");
	NEW_LINE;
	PUT (mark, width => 1);
        PLANIMETRY.area_circle (2.0);
        PLANE.get_coordinates (X1,Y1);

Best to include package names (except for I/O)


Previous topic | Next topic | Ada Home Page | Index
c-lokan@adfa.oz.au / 20 Feb 96