From: byhoe@greenlime.com (Adrian Hoe)
Subject: Re: Can you use arrays from another package ?
Date: 21 May 2002 23:13:05 -0700
Date: 2002-05-22T06:13:06+00:00 [thread overview]
Message-ID: <9ff447f2.0205212213.17c6f479@posting.google.com> (raw)
In-Reply-To: dstanbro-23D11A.09373422052002@mec2.bigpond.net.au
Dale Stanbrough <dstanbro@bigpond.net.au> wrote in message news:<dstanbro-23D11A.09373422052002@mec2.bigpond.net.au>...
> 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
SOmetimes it is difficult to say which is bad design. It depends on
the purpose and what is your approach in designing your software.
One still can have array A declared in package spec. In some cases,
you would want to declare private (or declare in the package body) and
have a procedure to read/write to the array. You hide it away from
other package but provide a nice way for access.
Sometimes, you just need to declare it public.
--
-- Adrian Hoe
-- http://adrianhoe.com
next prev parent reply other threads:[~2002-05-22 6:13 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
2002-05-22 1:47 ` Jeffrey Carter
2002-05-22 6:13 ` Adrian Hoe [this message]
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