Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!ukma!ukecc!agollum From: agollum@engr.uky.edu (Kenneth Herron) Newsgroups: comp.lang.pascal Subject: Re: Procedures or Functions as parameters Summary: Here's a way Message-ID: <2425@ukecc.engr.uky.edu> Date: 10 Jun 88 04:53:09 GMT References: <213@lafcol.UUCP> <2165@ucdavis.ucdavis.edu> <1240@csuna.UUCP> Reply-To: agollum@engr.uky.edu (Kenneth Herron) Followup-To: comp.lang.pascal Distribution: na Organization: Way down south in the land of Basketball Lines: 58 >>>Has anyone tried to pass procedures or functions as parameters within >>>user written procedures? >If you >look carefully at the manual for Turbo (Appendix B p 532) you'll see it >clearly stated that procedural or functional parameters are not allowed >in Turbo. (Actually it's page 520) Well, the database toolbox SORT unit manages it. It's kinda tricky though...let's see how well I can describe it without violating their copyright on the source code :-) 1) Define your procedures/functions like this: {$F+} {this is required} Procedure Foo; begin [...] end; {foo} Function Bar(var X, Y: byte): boolean; begin [...] end; {bar} {$F-} 2) Declare a pointer like this var GluePtr: Pointer; { generic pointer type } 3) Declare a function or procedure like this, with GluePtr declared outside it: {$F+} procedure CallProc; inline($FF/$1E/GluePtr); {CALL DWORD PTR GluePtr} function CallFunc(var x, y: byte):boolean; inline($FF/$1E/GluePtr); {CALL DWORD PTR GluePtr} {$F-} Note the actual parameter list should exactly match the parameter list of the function/procedure pointed to by GluePtr. You'll need to declare a different CallProc (with different names, natch) for a procedure with a different paramater list. Same for CallFunc. 4) Call the darn thing like this: GluePtr := @Foo; {Foo is a procedure with no arguments} CallProc; {Foo will be executed} GluePtr := @Bar; {Bar is a procedure with two byte args, boolean return} if CallFunc(x,y) then... For a more real-world example, check out the toolbox. Kenneth Herron