home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!utcsri!newsflash.concordia.ca!IRO.UMontreal.CA!iros1!shen
- From: shen@nil.IRO.UMontreal.CA (Yu Shen)
- Subject: Re: Turbo and Procs/Fns as params..
- In-Reply-To: dmurdoch@mast.queensu.ca's message of Mon, 16 Nov 1992 13: 05:29 GM
- Message-ID: <SHEN.92Nov16212135@nil.IRO.UMontreal.CA>
- Sender: news@IRO.UMontreal.CA
- Organization: Universite de Montreal -- Laboratoire Incognito
- References: <1992Nov4.190755.25383@polaris.utu.fi> <mByRTB4w165w@digsol.jpunix.com>
- <1992Nov11.104939.14727@jyu.fi> <1992Nov11.111534.1@uwovax.uwo.ca>
- <1e6qnoINNnr6@matt.ksu.ksu.edu>
- <dmurdoch.163.721919129@mast.queensu.ca>
- Date: Tue, 17 Nov 1992 02:21:35 GMT
- Lines: 75
-
- In article <dmurdoch.163.721919129@mast.queensu.ca> dmurdoch@mast.queensu.ca (Duncan Murdoch) writes:
-
- > Newsgroups: comp.lang.pascal
- > Path: IRO.UMontreal.CA!newsflash.concordia.ca!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!news.ccs.queensu.ca!slip203.telnet1.QueensU.CA!dmurdoch
- > From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
- > Lines: 33
- > Sender: news@knot.ccs.queensu.ca (Netnews control)
- > Organization: Queen's University
- > References: <1992Nov4.190755.25383@polaris.utu.fi> <mByRTB4w165w@digsol.jpunix.com> <1992Nov11.104939.14727@jyu.fi> <1992Nov11.111534.1@uwovax.uwo.ca> <1e6qnoINNnr6@matt.ksu.ksu.edu>
- > Date: Mon, 16 Nov 1992 13:05:29 GMT
-
- > In article <1e6qnoINNnr6@matt.ksu.ksu.edu> holland@matt.ksu.ksu.edu (Rich Holland) writes:
- >>Turbo Pascal *DOES* Allow you to pass Procedures and Functions as parameters.
- >>Unless I misinterpreted your comment....
- >
- >...but only if you pass them as a *pointer*
-
- > It's true that you don't pass the actual code around, but you don't need to
- > explicitly use pointers. For example:
-
- {$F+} { this is necessary, since procedures to be assigned must be far }
- >
- > function add(a,b:integer):integer;
- > begin add := a+b end;
-
- > function subtract(a,b:integer):integer;
- > begin subtract := a-b end;
-
- > type
- > binaryop = function(a,b:integer):integer;
-
- > var
- > someop : binaryop;
-
- > begin
- > someop := add;
- > writeln('Some op of 5 and 3 is ',someop(5,3));
- > end.
-
- > The implementation makes someop a pointer to the entry point of the add
- > function here, but the syntax hides that.
-
- > Duncan Murdoch
- > dmurdoch@mast.queensu.ca
-
- I just have a related problem that it seemed to me that member
- function can not be as value for such procedure variable.
-
- Here is the example modified from the above:
-
- AnObject = object
- function add(a,b:integer):integer; {wrap it into an object}
- end;
-
- function AnObject.add(a,b:integer):integer;
- begin add := a+b end;
-
- type
- binaryop = function(a,b:integer):integer;
-
- var
- someop : binaryop;
- theObject: AnObject;
- begin
- someop := theObject.add; {it may not work, here, though, I didn't
- try $F+}
- writeln('Some op of 5 and 3 is ',someop(5,3));
- end.
- --
- Yu Shen
- Dept. d'Informatique et Recherche Operationnelle
- University de Montreal, C.P. 6128 Succ. A.
- Montreal, Que. Canada, H3C 3J7
-
- (514) 342-7089 (H) shen@IRO.UMontreal.Ca
-