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-Thread: 103376,910a48a538936849 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!79g2000cws.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: how to import a package Date: 11 Dec 2006 08:22:00 -0800 Organization: http://groups.google.com Message-ID: <1165854120.159109.265380@79g2000cws.googlegroups.com> References: <1165371252.358817.57840@80g2000cwy.googlegroups.com> <4577dc92$1_1@glkas0286.greenlnk.net> <7ft8le.vk1.ln@hunter.axlog.fr> <1165817760.736164.218530@73g2000cwn.googlegroups.com> <1165819804.449958.305980@73g2000cwn.googlegroups.com> <1165830005.15844.5.camel@localhost> <1165846777.475130.199390@f1g2000cwa.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1165854126 9405 127.0.0.1 (11 Dec 2006 16:22:06 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 11 Dec 2006 16:22:06 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: 79g2000cws.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news2.google.com comp.lang.ada:7890 Date: 2006-12-11T08:22:00-08:00 List-Id: markww wrote: > Ok I just broke down and wrote the test function to take a specific > PERSON_REC type to add into a new node. The program compiles and runs > as expected, but I just lost my generics support by doing this, I > think: > > procedure Add_Record(GenericData : PERSON_REC) is > Temp : gNode.Node_Ptr; > begin > > Temp := new gNode.Node; > Temp.Data := GenericData; > end Add_Record; > So yes now it runs ok and I can print the contents of the linked list > and see that a person record was added into the Data member. > > But now I can't use this Add_Record function to store some other type > of user defined data, it will only work with PERSON_RECs. > > I'm sorry, I still don't understand how to just pass a generic through > as a parameter! If I understand what you're trying to do, then I think you want to put Add_Record inside the generic. You can add this to the GenericNode package: procedure Add_Record (GenericData: T); and then set up a package body for GenericNode that contains the body of Add_Record. The effect is that when GenericNode is instantiated (package is new GenericNode...) with type PERSON_REC or ANOTHER_REC or whatever, you will also get a new Add_Record, inside gNode, to add records of that type. You'll probably have to do something additional. The way you've written Add_Record above, it assigns Temp to be a pointer to a new node, but then Temp isn't stored anywhere else, so that the new node you've just created is abandoned and no one can ever access it again. How you solve this depends on your particular design, but you may need to turn Add_Record into a function that returns a Node_Ptr, or add an OUT parameter whose type is Node_Ptr. Hope this helps, -- Adam