comp.lang.ada
 help / color / mirror / Atom feed
* Calling a record type's methods (functions or procedure) when record is in an array
@ 2020-01-17 23:30 Mace Ayres
  2020-01-18 12:31 ` Simon Wright
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Mace Ayres @ 2020-01-17 23:30 UTC (permalink / raw)


My package 'trunks.ads' includes 
...
type a_trunk;.

function set_lock ...  return lock_state;

function post_val(v:integer) --- return integer
...
type a_trunk is
  record
     id : ,,,
    val
    ...
    lock  : lock_state    -- enumeration type defined earlier (open, locked)
  end record;

Package body 'trunks.adb  includes ...

function set_lock (  ..... not relevant

function post_val i(v:integer)  return integer is ..return v;

------
In package 1 I have a multi dimension array of type a_truck that I get to with
..
loop de loop i,j
my_trunk_array (i)(j)
..
-------

To modify the item val in the trunk at array (5)(3) I code..

... my_truck_arrary(5)(3).val := trunks.post_val(N)

rather than my_tunk_arrary(5)(3).val := N

so I don't directly access the a_trunk record's value fields directly

-- I have to add the private part too, to hide the inners of type a_trunk.

It seem a little convoluted, but I see no other way to manipulate my a_truck type records that only 'exist' the array.

I am just learning Ada. Is this reasonable?





^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-01-24  9:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-17 23:30 Calling a record type's methods (functions or procedure) when record is in an array Mace Ayres
2020-01-18 12:31 ` Simon Wright
2020-01-18 18:02 ` Mace Ayres
2020-01-18 20:53   ` Simon Wright
2020-01-21 20:51   ` Shark8
2020-01-21 23:17     ` Jeffrey R. Carter
2020-01-23 15:00     ` joakimds
2020-01-23 15:02       ` joakimds
2020-01-23 16:51         ` Simon Wright
2020-01-24  9:47           ` joakimds
2020-01-23 20:15       ` Optikos
2020-01-19 15:06 ` Mace Ayres

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