How to pass a procedure as a parameter in TP4. 
Author Message
 How to pass a procedure as a parameter in TP4.

Versions of Turbo Pascal prior to 5.5 (or possibly 5.0) do not allow passing a
procedure as a parameter. Here is a method that overcomes this limitation. I
have one question concerning this method, though. How does one change the in-
line code to use a variable of type pointer (instead of type word) for the
address of the parameter? Or, more to the point, how does one pass a function
as a parameter to a procedure that is in another Turbo Pascal unit using TP4?

Brent L. Carruth, PhD

--------------------------------Begin Program---------------------------------
{ This Turbo Pascal 4.0 program passes a function as a parameter to a proce-
dure. It uses a method due to Mike Babulic of Calgary, Alberta Canada which is
described in the Turbo Pascal 3.0 program ProcParm.PAS Version 2.1 86/05/09.
The program ProcParm.PAS is found in the file PROCPARM.ZIP on ftp.simtel.net }

var x,y:real;

function f(x:real) : real;
  begin
    f:=2*x;
  end;

function f1(x:real;p:word) : real;
begin
  Inline(
    $8B/$66/$02/    {  SS:MOV  SP,[BP+2] ;Exchange Return Addr & Func Ptr}
    $87/$66/$04/    {  SS:XCHG SP,[BP+4] }
    $89/$66/$02/    {  SS:MOV  [BP+2],SP }
    $89/$EC/        {     MOV  SP,BP     ;Standard Turbo Return (if no Parms)}
    $5D/            {     POP  BP        }
    $C3             {     RET            ;Near Return }
    )
end;

procedure EvalF(var y:real;x:real;p:word);
  begin
    y:=f1(x,p);
  end;

begin
  x:=5;
  Evalf(y,x,Ofs(f));
  Writeln('f(x)=2x at x=',x:3:1,' is ',y:3:1);
end.
---------------------------------End Program----------------------------------



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Passing a pointer to a procedure/function as a parameter in a procedure

2. Passing parameters to stored procedure.

3. Passing TMemoField as a TStringList parameter to a procedure

4. Passing NULL parameters to a stored procedure

5. Passing Procedures as Parameters in TP 7.0

6. Passing blob parameter to stored procedure

7. passing procedures as arguments for another procedure in Turbo pascal

8. passing procedures as arguments for another procedure in Turbo pascal

9. passing procedures as arguments for another procedure in Tu

10. Procedure as parameter in procedure

11. Pass a TTable as Parameter to another object.

12. Passing Parameters to an Update Query

 

 
Powered by phpBB® Forum Software