From: Mace Ayres <maceayres0@gmail.com>
Subject: Calling a record type's methods (functions or procedure) when record is in an array
Date: Fri, 17 Jan 2020 15:30:52 -0800 (PST)
Date: 2020-01-17T15:30:52-08:00 [thread overview]
Message-ID: <b820f7d0-1b5e-4e1d-9dd1-3f873e2f13e1@googlegroups.com> (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?
next reply other threads:[~2020-01-17 23:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-17 23:30 Mace Ayres [this message]
2020-01-18 12:31 ` Calling a record type's methods (functions or procedure) when record is in an array 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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox