comp.lang.ada
 help / color / mirror / Atom feed
From: gisle@apal.ii.uib.no (Gisle S�lensminde)
Subject: Re: "Dynamic" object
Date: 2000/03/06
Date: 2000-03-06T00:00:00+00:00	[thread overview]
Message-ID: <slrn8c7ouf.kji.gisle@apal.ii.uib.no> (raw)
In-Reply-To: slrn8c6vka.2fr.randhol@kiuk0156.chembio.ntnu.no

Preben Randhol wrote:

>I'm wondering how to do the following in Ada 95.
>
>I want to have a small program as a frontend to a database. Thus the
>program needs to read the definition of the db and then generate the
>proper GUI for this. This I think I know how to to, but the problem is
>how do I define a type that contains the different fields so that I can
>put it in a linked list?
>
>Example:
>
>Field 1: First_Name (string of size 30)
>Field 2: Sirname    (string of size 40)
>Field 3: Age        (integer of size 3)
>...
>Field n: Address    (string of size 80)
>
>Any hints much appreciated.


I have some problem understanding what problem is. To get a more precise
answer (at least from me), you should give more details of your problem.

Is you problem:

1) The problem of making a type representing the data you describe,
   and put that in a linked list. (probably not, you would have
   figured that out yourself!) 

-- a type for your table entries

type table_entry is 
  record
    first_name : string(1..30);
    surname    : string(1..40);
    age        : natural;                          
    ....  
    address    : string(1..80);
  end record;

-- instaniate a generic linked list with your table entry type
package entrylist is new linked_lists(element => table_entry)


2) You have several kinds of tables, and want to make a hetrogenous 
list of table entries. Then you can make a controlled table type
holding a pointer to the actual data. The type is made controlled
to ease memory handling, it could have been just tagged. Since the 
different table entry types typically will have different sizes, 
I have used an access type poining to super_entry'class. 

with ada.finalization; use ada.finalization;

-- super type for all tables (not called entry for obvious reason :-)
type super_entry is tagged null record;

-- the table types, like in (1)
type table1_entry is new super_entry with record ... end record;
type table1_entry is new super_entry with record ... end record;
     
type entry_access is access table_entry'class;

type entry_holder is new controlled with
  record
     T : entry_access;
  end record;

package entrylists is new linked_lists(element => entry_holder);

Then you should implement the initialize, adjust and finalize
for entry_holder.

I don't know if this is an answer to you question, but if not
please tell me.

--
Gisle S�lensminde ( gisle@ii.uib.no )   

ln -s /dev/null ~/.netscape/cookies




  reply	other threads:[~2000-03-06  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-06  0:00 "Dynamic" object Preben Randhol
2000-03-06  0:00 ` Gisle S�lensminde [this message]
2000-03-06  0:00   ` Preben Randhol
2000-03-07  0:00     ` Simon Wright
2000-03-08  0:00       ` Preben Randhol
2000-03-08  0:00     ` Gisle S�lensminde
2000-03-08  0:00       ` Preben Randhol
replies disabled

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