From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e5f2c12e14eeb0f5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-21 23:13:06 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: byhoe@greenlime.com (Adrian Hoe) Newsgroups: comp.lang.ada Subject: Re: Can you use arrays from another package ? Date: 21 May 2002 23:13:05 -0700 Organization: http://groups.google.com/ Message-ID: <9ff447f2.0205212213.17c6f479@posting.google.com> References: NNTP-Posting-Host: 210.186.172.210 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1022047986 11099 127.0.0.1 (22 May 2002 06:13:06 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 22 May 2002 06:13:06 GMT Xref: archiver1.google.com comp.lang.ada:24501 Date: 2002-05-22T06:13:06+00:00 List-Id: Dale Stanbrough wrote in message news:... > 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