Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!eru!hagbard!sunic!dkuug!diku!ballerup From: ballerup@diku.dk (Per Goetterup) Newsgroups: comp.lang.pascal Subject: Procedures and functions as parameters to other procs/funcs (TP 6.0) Message-ID: <1991Feb4.141222.28662@odin.diku.dk> Date: 4 Feb 91 14:12:22 GMT Sender: news@odin.diku.dk (Netnews System) Organization: Department of Computer Science, U of Copenhagen Lines: 53 I was also fooling around with this concept, in TP 6.0 though. I was trying to do something like this: function a(x: integer): integer; begin { do something } end; function b(x: integer): integer; begin { do something else } end; procedure qaz(var f: function; .... ); begin writeln(f(23)); end; begin qaz(a, ...); qaz(b, ...); end. TP 6.0 won't let me do that. Then I tried this version of qaz: procedure qaz(p: pointer; ... ); var f: function(x: integer): integer absolute p; begin writeln(f(23)); end; This works - in a way. Both functions a and b gets called in the right order, BUT the value of x inside them is wrong! - After several (lots) of calls, the program (and TP) crashes, thus indicating stack problems. Has anybody else tried this in TP? - As TP allow that VAR-declaration, it must be supported in some way or other. Removing the parameter in the declaration of f, or making it a VAR-parameter doesn't work either because the program can't be compiled like that. Hints? - Use objects perhaps? (HOW?) Anything would be appreciated! Per. -- | Per Gotterup | "The most merciful thing in the | | Student, DIKU (Dept. of Comp. Sci.) | world, I think, is the inability | | University of Copenhagen, Denmark | of the human mind to correlate all | | Internet: ballerup@freja.diku.dk | its contents." - H.P. Lovecraft - |