Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uunet!zephyr.ens.tek.com!tekgen!penguin.uss.tek.com!decomyn From: decomyn@penguin.uss.tek.com Newsgroups: comp.lang.pascal Subject: Re: TP5.5: Can't store method in procedure variable Keywords: Method Object Procedure TP5.5 Message-ID: <6963@tekgen.BV.TEK.COM> Date: 3 Dec 90 16:27:51 GMT References: <1990Dec3.061013.22258@ux1.cso.uiuc.edu> Sender: news@tekgen.BV.TEK.COM Reply-To: decomyn@penguin.uss.tek.com (Vergil William de Comyn) Organization: Tektronix, Inc., Beaverton, OR. Lines: 58 In article <1990Dec3.061013.22258@ux1.cso.uiuc.edu> dslg0849@uxa.cso.uiuc.edu (Daniel S. Lewart) writes: >I am attempting to store an object's method in a procedure variable in TP5.5. >However, I get a compiler error in the assignment statement. What am I doing >wrong? Is there some way to do what I want to do? >------------------------------------------------------------------------------- >{$F+} >type > ObjectType = object > procedure Method; > end; >var > Obj: ObjectType; > ProcVar: procedure; > >procedure ObjectType.Method; begin end; >procedure Proc; begin end; > >Begin > ProcVar := Proc; { This compiles } > ProcVar := Obj.Method; { This doesn't } >End. >------------------------------------------------------------------------------- >TEST.PAS(15): Error 143: Invalid procedure or function reference. The problem is that you are thinking of an object's methods as procedures. Technically, they are not procedures, and you can't treat them the same as independent procedures in many ways... including, apparently, this one. Unfortunately, I can't think of an immediate answer. You might try ProcVar := @Obj.Method, but I doubt that it will work. Also, take a peek at how the Procedure variables are stored. You might be able to force the correct calling address in by creating an absolute variable record at the Procedure variable location, something like this: type Testrec = Record segm : word; offs : word; End; var [...] ProcCall : Testrec absolute ProcVar; Begin Testrec.segm:=Seg(Obj.Method); Testrec.offs:=Ofs(Obj.Method); [...] etcetera. It may or may not work. (Note: the correct order may be offset first: I haven't looked at any generated code with that in mind) Good luck. ------------------------------------------------------------------------------- Brendt Hess a.k.a. | Disclaimer: Opinions? I don't even work here! Vergil William de Comyn a.k.a. |----------------------------------------------- Payne Hirds | Life is not a zero-sum game: decomyn@penguin.uss.tek.com | don't treat it as such. Brought to you by Super Global Mega Corp .com