comp.lang.ada
 help / color / mirror / Atom feed
From: "Adam Beneschan" <adam@irvine.com>
Subject: Re: how to import a package
Date: 11 Dec 2006 08:22:00 -0800
Date: 2006-12-11T08:22:00-08:00	[thread overview]
Message-ID: <1165854120.159109.265380@79g2000cws.googlegroups.com> (raw)
In-Reply-To: 1165846777.475130.199390@f1g2000cwa.googlegroups.com

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 <whatever> 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




  parent reply	other threads:[~2006-12-11 16:22 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-06  2:14 how to import a package markww
2006-12-06  3:06 ` Adam Beneschan
2006-12-06  3:34   ` markww
2006-12-06  9:18     ` Simon Wright
2006-12-06 19:47 ` Jeffrey R. Carter
2006-12-06 23:56   ` markww
2006-12-07  1:18     ` Björn Persson
2006-12-07  1:26     ` Brian May
2006-12-07  4:14       ` markww
2006-12-07  4:40         ` Brian May
2006-12-07  9:32           ` Stuart
2006-12-07 11:21             ` Jean-Pierre Rosen
2006-12-11  6:16               ` markww
2006-12-11  6:50                 ` markww
2006-12-11  9:40                   ` Georg Bauhaus
2006-12-11 14:19                     ` markww
2006-12-11 15:03                       ` Dmitry A. Kazakov
2006-12-11 16:22                       ` Adam Beneschan [this message]
2006-12-11 20:28                       ` Jeffrey R. Carter
2006-12-12  3:19                         ` markww
2006-12-12  3:31                           ` Jeffrey R. Carter
2006-12-12  9:03                           ` Stuart
2006-12-12 10:56                           ` Georg Bauhaus
2006-12-11  7:00                 ` Simon Wright
2006-12-07  4:06     ` Jeffrey R. Carter
replies disabled

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