From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,94b44ecb42c031b9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-08-31 14:57:29 PST Path: supernews.google.com!sn-xit-02!sn-east!supernews.com!feed2.onemain.com!feed1.onemain.com!xfer13.netnews.com!netnews.com!ams-newsfeed.speedport.net!newsfeed.speedport.net!colt.net!newspeer.clara.net!news.clara.net!dispose.news.demon.net!demon!news.demon.co.uk!demon!assen.demon.co.uk!not-for-mail From: john@assen.demon.co.uk.nospam (John McCabe) Newsgroups: comp.lang.ada Subject: Re: Searching for an object Date: Thu, 31 Aug 2000 21:55:15 GMT Message-ID: <39aed239.14592091@news.demon.co.uk> References: <87og2q9yyp.fsf@moon.mteege.de> NNTP-Posting-Host: assen.demon.co.uk X-NNTP-Posting-Host: assen.demon.co.uk:158.152.218.101 X-Trace: news.demon.co.uk 967758994 nnrp-02:15119 NO-IDENT assen.demon.co.uk:158.152.218.101 X-Complaints-To: abuse@demon.net X-Newsreader: Forte Free Agent 1.21/32.243 Xref: supernews.google.com comp.lang.ada:448 Date: 2000-08-31T21:55:15+00:00 List-Id: Matthias Teege wrote: >I've defined the following type: > >type customer is record > aname : String( 1..25); > bname : String( 1..25); >end record; > >Then I create some objects of this type and save all of >them in an table. > >Now I want to find a special object with a find procedure >like this (not authentic Ada Code :-)): > >procedure find ( Field : in String; > What : in String; > Result: out String) is > >while end_of_table is false loop > read(object); > if object.Field = What then -- field should be 'aname' > -- or 'bname' > Result := object.Field; > exit; -- We have found it > end if >end loop; >end find; > >I want to search in all Record "Fields" depend on the >procedure parameter. > >How is the Ada way? If I understand the requirement correctly, a way to do it would be to define: type Comparator_Type is access function (Left : Customer; Right : String) return Boolean; And define procedure find (What : in string; Comparator : in Comparator_Type; Result : out String) is function "=" renames Comparator.all; begin ... if Object = What then ... end find; So in a client of this package you would have: procedure client is function Match_Afield (Left : other_package.customer; Right : string) return boolean is begin return Left.afield = right; end Match_Afield; function Match_Bfield (Left : other_package.customer; Right : string) return boolean is begin return Left.bfield = right; end Match_Bfield; begin other_package.find (what => "blah", comparator => Match_Afield'access, result => local_result); end client; Or something like that. This would all need to be modified and syntax checked etc. You could also make the find function a generic that is instantiated with an "=" operation. John Best Regards John McCabe