From: eru.mt.luth.se!lunic!sunic!sunic2!seunet!lin.foa.se!eriks@bloom-beacon.mi t.edu (Erik Svensson FOA2)
Subject: Re: associate functions to objects
Date: 16 Apr 92 07:57:01 GMT [thread overview]
Message-ID: <1992Apr16.075701.5312@lin.foa.se> (raw)
consp10@bingsunb.cc.binghamton.edu (Julian Insan Kamil) writes:
>I'm working on a project for a Software Engineering class, and we're using Ada
to
>develop a simple database management application. My part is on building the u
ser
>interface for the app. One of the data type that we're using is called an
>EntryBoard which is supposed to manage a list of other objects like Fields,
>Buttons, Titles, etc. Each of those objects should be attached to a function t
hat
>will be called whenever that object is selected (sort of like callback
>functions). Now, how do you attach functions to objects? I consulted my Ada
>references and it seems that Ada doesn't allow passing functions as a paramete
r
>to a procedure (the way I did it in C++ to implement the same behavior). I nee
d
>hints and advice and examples on how to do this kind of things. Will anybody h
elp
>me with some light?
If you're going to use generics you can send a procedure or a function as an
argument when you instantiate (sp?) the package.
(this is from the top of my head, so there might be some errors)
generic
type Type_1 is (<>);
type Type_2 is private;
with procedure Foo(a : in out Type_1); -- Your supplied procedure
package Bar is
procedure Foo_Bar(Some_Parameter : in Type_2);
end Bar;
then in your package body:
package body Bar is
procedure Foo_Bar(Some_Parameter : in Type_2) is
begin
.
.
Foo(some_other_parameter);
.
.
end Foo_Bar;
end Bar;
You instantiate this with
procedure a_procedure(a : Type_2); -- Declare your procedure
procedure a_procedure(a : Type_2) is -- the body
begin
(some code)
end a_procedure;
package My_Bar is new Bar(A_Type,another_type,a_procedure);
Simple as that.
It's in LRM 12.1.3, 12.3.6.
>-Julian Insan Kamil
>Computer Consultant at SUNY-Binghamton
>email: consp10@bingsunb.cc.binghamton.edu
>email: consp10@bingvaxu.cc.binghamton.edu
--
Erik Svensson Research Officer
Guided Weapons Division National Defense Research Establishment (FOA)
Stockholm Sweden
net.address: eriks@fenix.lin.foa.se
&& This .sig is protected by SIGinfectant(tm). Look for the &&, a sure sign of
quality .sig protection. &&
next reply other threads:[~1992-04-16 7:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1992-04-16 7:57 eru.mt.luth.se!lunic!sunic!sunic2!seunet!lin.foa.se!eriks [this message]
-- strict thread matches above, loose matches on Subject: below --
1992-04-14 22:53 associate functions to objects Robert I. Eachus
1992-04-14 5:21 elroy.jpl.nasa.gov!usc!rpi!sarah!newserve!bingsuns.cc.binghamton.edu!cons
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox