home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pascal / 6643 < prev    next >
Encoding:
Text File  |  1992-11-17  |  3.0 KB  |  91 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!utcsri!newsflash.concordia.ca!IRO.UMontreal.CA!iros1!shen
  3. From: shen@nil.IRO.UMontreal.CA (Yu Shen)
  4. Subject: Re: Turbo and Procs/Fns as params..
  5. In-Reply-To: dmurdoch@mast.queensu.ca's message of Mon, 16 Nov 1992 13: 05:29 GM
  6. Message-ID: <SHEN.92Nov16212135@nil.IRO.UMontreal.CA>
  7. Sender: news@IRO.UMontreal.CA
  8. Organization: Universite de Montreal -- Laboratoire Incognito
  9. References: <1992Nov4.190755.25383@polaris.utu.fi> <mByRTB4w165w@digsol.jpunix.com>
  10.     <1992Nov11.104939.14727@jyu.fi> <1992Nov11.111534.1@uwovax.uwo.ca>
  11.     <1e6qnoINNnr6@matt.ksu.ksu.edu>
  12.     <dmurdoch.163.721919129@mast.queensu.ca>
  13. Date: Tue, 17 Nov 1992 02:21:35 GMT
  14. Lines: 75
  15.  
  16. In article <dmurdoch.163.721919129@mast.queensu.ca> dmurdoch@mast.queensu.ca (Duncan Murdoch) writes:
  17.  
  18. > Newsgroups: comp.lang.pascal
  19. > 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
  20. > From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
  21. > Lines: 33
  22. > Sender: news@knot.ccs.queensu.ca (Netnews control)
  23. > Organization: Queen's University
  24. > 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>
  25. > Date: Mon, 16 Nov 1992 13:05:29 GMT
  26.  
  27. > In article <1e6qnoINNnr6@matt.ksu.ksu.edu> holland@matt.ksu.ksu.edu (Rich Holland) writes:
  28. >>Turbo Pascal *DOES* Allow you to pass Procedures and Functions as parameters. 
  29. >>Unless I misinterpreted your comment....
  30. >
  31. >...but only if you pass them as a *pointer*
  32.  
  33. > It's true that you don't pass the actual code around, but you don't need to 
  34. > explicitly use pointers.  For example:
  35.  
  36. {$F+}  { this is necessary, since procedures to be assigned must be far }
  37. >          
  38. >   function add(a,b:integer):integer;
  39. >   begin add := a+b end;
  40.  
  41. >   function subtract(a,b:integer):integer;
  42. >   begin subtract := a-b end;
  43.  
  44. >   type
  45. >     binaryop = function(a,b:integer):integer;
  46.  
  47. >   var
  48. >     someop : binaryop;
  49.  
  50. >   begin
  51. >     someop := add;
  52. >     writeln('Some op of 5 and 3 is ',someop(5,3));
  53. >   end.
  54.  
  55. > The implementation makes someop a pointer to the entry point of the add 
  56. > function here, but the syntax hides that.
  57.  
  58. > Duncan Murdoch
  59. > dmurdoch@mast.queensu.ca
  60.  
  61. I just have a related problem that it seemed to me that member
  62. function can not be as value for such procedure variable.
  63.  
  64. Here is the example modified from the above:
  65.  
  66. AnObject = object
  67.    function add(a,b:integer):integer; {wrap it into an object}
  68. end;
  69.  
  70. function AnObject.add(a,b:integer):integer;
  71.    begin add := a+b end;
  72.  
  73.    type
  74.      binaryop = function(a,b:integer):integer;
  75.  
  76.    var
  77.      someop : binaryop;
  78.      theObject: AnObject;    
  79.    begin
  80.      someop := theObject.add; {it may not work, here, though, I didn't
  81. try $F+}
  82.      writeln('Some op of 5 and 3 is ',someop(5,3));
  83.    end.
  84. --
  85. Yu Shen
  86. Dept. d'Informatique et Recherche Operationnelle
  87. University de Montreal, C.P. 6128 Succ. A.
  88. Montreal, Que. Canada, H3C 3J7
  89.  
  90. (514) 342-7089 (H) shen@IRO.UMontreal.Ca
  91.