From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 16 Apr 92 07:57:01 GMT 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 Message-ID: <1992Apr16.075701.5312@lin.foa.se> List-Id: 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. &&