comp.lang.ada
 help / color / mirror / Atom feed
From: Dale Stanbrough <dstanbro@bigpond.net.au>
Subject: Re: Can you use arrays from another package ?
Date: Tue, 21 May 2002 23:37:43 GMT
Date: 2002-05-21T23:37:43+00:00	[thread overview]
Message-ID: <dstanbro-23D11A.09373422052002@mec2.bigpond.net.au> (raw)
In-Reply-To: acehkr$2v5$1@saturn.bton.ac.uk

Jon wrote:

> say the main program is calle MAIN.ADB
> 
> and uses 2 packages X and Y
> 
> if there is an array of records in X called A.
> 
> how do i use the array A in Y ?
> 
> e.g
> 
> package body X is
>     type R is record
>         hi : string;
>         bye : integer;
>     end record;
> 
>     A : array(1..10) of R;
> 
> end X;
> 
> 
> now in Y, how do i use that array ? ive tried this :

you need a "with, use" clause at the start of either 
Y's package spec, or it's package body.

You'll also need to wrap up the call to get inside
a procedure...

e.g.


  with X; use X;
> package body Y is

procedure Get_Hi is
begin
>     get( X.A(1).hi );
end;

> 
> end Y;


That's how to get it working; however i think it's a bad
design. My design rule is "never declare variables in a
package spec".

The declaration of A would be better in Main, and then
you pass it into procedure Get_Hi as a parameter.

A big mistake that people make it to treat packages as
objects - a good way to view them is just as a place where
type declarations and subprograms go.
(this is not quite the only way to view them, but it's a 
good first step).


Dale



  parent reply	other threads:[~2002-05-21 23:37 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-21 22:28 Can you use arrays from another package ? Jon
2002-05-21 23:31 ` tmoran
2002-05-21 23:37 ` Dale Stanbrough [this message]
2002-05-22  1:47   ` Jeffrey Carter
2002-05-22  6:13   ` Adrian Hoe
2002-05-22  1:52 ` Robert Dewar
2002-05-22 12:11   ` Jon
2002-05-22 12:36     ` Preben Randhol
2002-05-22 15:16       ` Jon
2002-05-22 19:17         ` Preben Randhol
2002-05-22 22:22       ` Robert Dewar
2002-05-24  4:17         ` Richard Riehle
2002-05-24 13:41           ` Larry Kilgallen
2002-06-01 11:19           ` Georg Bauhaus
2002-05-24 10:07         ` John English
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox