From: Simon Wright <simon@pushface.org>
Subject: Re: Calling a record type's methods (functions or procedure) when record is in an array
Date: Sat, 18 Jan 2020 12:31:23 +0000
Date: 2020-01-18T12:31:23+00:00 [thread overview]
Message-ID: <ly36cdymhw.fsf@pushface.org> (raw)
In-Reply-To: b820f7d0-1b5e-4e1d-9dd1-3f873e2f13e1@googlegroups.com
Mace Ayres <maceayres0@gmail.com> writes:
> 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
? this code does indeed access the value fields directly!
> -- I have to add the private part too, to hide the inners of type
> a_trunk.
You're looking for an accessor (though accessors aren't always a good
idea; there might be checks needed, attributes may be related so you
need to deal with more than one at the same time, eg coordinates):
package Mace is
type Thing is private;
procedure Set_Attribute (Into : in out Thing; Value : Integer);
function Get_Attribute (From : Thing) return Integer;
private
type Thing is record
Attribute : Integer;
end record;
end Mace;
package body Mace is
procedure Set_Attribute (Into : in out Thing; Value : Integer) is
begin
Into.Attribute := Value;
end Set_Attribute;
function Get_Attribute (From : Thing) return Integer
is (From.Attribute);
end Mace;
next prev parent reply other threads:[~2020-01-18 12:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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