Board index » delphi » Procedure as parameter in procedure

Procedure as parameter in procedure

Hi,

I'm trying to figure out how to use a procedure as a parameter in a
procedure. I'd be very thankful to anyone who takes the trouble of
giving me a simply example.

Thanks,

Helle

Hjemmeside/Homepage: http://www.ifi.ntnu.no/~haugenes/

 

Re:Procedure as parameter in procedure


  hauge...@ifi.ntnu.no (Helle Haugenes) wrote:

 HH> I'm trying to figure out how to use a procedure as a parameter in a
 HH> procedure. I'd be very thankful to anyone who takes the trouble of
 HH> giving me a simply example.

 Look at the following Extended Pascal example:

 program ffexpm ( input, output ) ;
 var a,b,c,d,e,f: real ;
     s : string ( 20 ) ;

   function func1 ( p1, p2 : real ) : real ;
   begin
        func1 := sqr(p1) + sqr(p2) ;
   end ;

   function func2 ( p1, p2 : real ) : real ;
   begin
        func2 := sqr(p1) + sqr(p2) + p1 * p2 ;
   end ;

   function func3 ( p1, p2 : real ) : real ;
   begin
        func3 := sqr(p1) + sqr(p2) - p1 ** p2 ;
   end ;

   function func ( function p ( p1, p2:real ):real; p1,p2:real ):real ;
   begin
      func := sqr ( p ( p1, p2 ) ) ;
   end ;

 begin
      writeln (' Please enter values for a,b,c,d,e,f:' ) ;
      readln ( a,b,c,d,e,f ) ;
      writeln ( func( func1,a,b ):15:10, ' ', func(func2,c,d):15:10,
             ' ', func(func3,e,f):15:10 ) ;
 end.

 Kind regards
 F. Pluennecke

 -----------------------------------------------------------------------------
 Friedrich Pluennecke       Tel: 49-5174-1637                 f...@pluennecke.de
 Hinterm Dorfe 21           Fax: 49-5174-92101        http://www.pluennecke.de
 D-38268 Lengede   Pascal-Info: http://www.pluennecke.de/prospero/proindex.htm
 -----------------------------------------------------------------------------

Re:Procedure as parameter in procedure


  hauge...@ifi.ntnu.no (Helle Haugenes) wrote:

 HH> I'm trying to figure out how to use a procedure as a parameter in a
 HH> procedure. I'd be very thankful to anyone who takes the trouble of
 HH> giving me a simply example.

 Look at the following Extended Pascal example (it uses functions instead
of procedures, but demonstrates the method) :

 program ffexpm ( input, output ) ;
 var a,b,c,d,e,f: real ;
     s : string ( 20 ) ;

   function func1 ( p1, p2 : real ) : real ;
   begin
        func1 := sqr(p1) + sqr(p2) ;
   end ;

   function func2 ( p1, p2 : real ) : real ;
   begin
        func2 := sqr(p1) + sqr(p2) + p1 * p2 ;
   end ;

   function func3 ( p1, p2 : real ) : real ;
   begin
        func3 := sqr(p1) + sqr(p2) - p1 ** p2 ;
   end ;

   function func ( function p ( p1, p2:real ):real; p1,p2:real ):real ;
   begin
      func := sqr ( p ( p1, p2 ) ) ;
   end ;

 begin
      writeln (' Please enter values for a,b,c,d,e,f:' ) ;
      readln ( a,b,c,d,e,f ) ;
      writeln ( func( func1,a,b ):15:10, ' ', func(func2,c,d):15:10,
             ' ', func(func3,e,f):15:10 ) ;
 end.

 Kind regards
 F. Pluennecke

 -----------------------------------------------------------------------------
 Friedrich Pluennecke       Tel: 49-5174-1637                 f...@pluennecke.de
 Hinterm Dorfe 21           Fax: 49-5174-92101        http://www.pluennecke.de
 D-38268 Lengede   Pascal-Info: http://www.pluennecke.de/prospero/proindex.htm
 -----------------------------------------------------------------------------

Other Threads