[comp.sys.mac.programmer] Procedure variables in LSP

marty@june.cs.washington.edu (Marty Sirkin) (05/03/89)

Are there any?  I know that there are procedure arguments to other
procedures, but I need to save a procedure reference with each window, and
call on the procedure associated with the current window at certain times.

Any suggestions are welcome.  Also, if anyone has an inline procedure that
would do the trick I'd appreciate it.

						Thanks,
						Marty Sirkin
						marty@june.cs.washington.edu

siegel@endor.harvard.edu (Rich Siegel) (05/03/89)

In article <8083@june.cs.washington.edu> marty@june.cs.washington.edu (Marty Sirkin) writes:
>Are there any?  I know that there are procedure arguments to other
>procedures, but I need to save a procedure reference with each window, and
>call on the procedure associated with the current window at certain times.

	It sounds like objects are the ideal solution for you. Consult
the ObjectDraw demo program, particularly the TWindow class, for some hints
on how to tie objects to windows and have them work for you.

		--Rich


~~~~~~~~~~~~~~~
 Rich Siegel
 Staff Software Developer
 Symantec Corporation, Language Products Group
 Internet: siegel@endor.harvard.edu
 UUCP: ..harvard!endor!siegel

 "She told me to make myself comfortable, so I pulled down my pants
 and sat in the pudding." -Emo Phillips
~~~~~~~~~~~~~~~

ksitze@nmsu.edu (Kevin Sitze) (05/04/89)

Marty Sirkin wrote:
>Are there any?  I know that there are procedure arguments to other
>procedures, but I need to save a procedure reference with each window, and
>call on the procedure associated with the current window at certain times.

>Any suggestions are welcome.  Also, if anyone has an inline procedure that
>would do the trick I'd appreciate it.

Define an inline procedure something like below:

function DoMyWindowRoutine (var evt : EventRecord;
			    whichProc : ProcPtr) : longint;
inline 	$2058,		{	movea.l	(sp)+,	a0	}
	$4E90;		{	jsr	(a0)		}

You can put any number of parameters in the call as long as the last
parameter is the pointer to the procedure to call.  In this instance,
the procedure that is being called should look like this:

function CalledProc (var evt : EventRecord) : longint;

Notice that whichProc no longer exists in the parameter record.  This
is because the inline function removed the pointer to the procedure
from the top-of-stack (where it was placed by LSP when it made the
call) and used this pointer to call the procedure.  Also notice that
this is a function call, LSP (or any other pascal for that matter)
makes room on the stack for the function result before pushing any
parameters.  The parameters are then pushed onto the stack from left
to right so the last parameter is on top of the stack when pascal
makes the call.  Be sure to get those hex numbers right because who
knows what will happen if you don't  (I hope I did! :-))

More than you ever wanted to know about machine architecture...

Finally: I really don't suggest you do what your thinking of because:

1) Whenever you make a new window 'type', you have to write an entire
set of routines to support that window.  Using the Object support that
LSP 2.0 has (and storing the object into the refcon of the window)
gives the advantage that one routine can be used to delegate events to
internal routines without rewriting loads of code.  (Objects hold
quite a few advantages over other methods, even the limited object
support that LSP provides, I suggest you check out books like 'Object
oriented programming for the Macintosh,' and such.)

2) It can be really easy to corrupt the stack (or other system
structures) and provide loads of system errors, restarts, etc to the
poor programmer if INLINES are used extensively (and wrong).

			-Kelesi

p.s. I posted this on news because I figured there were others out
there that may have some use for these routines...
--
----------------------------------------------------------------------
    _______________     |
   |  ___________  |    |     From the Macintosh of:
   | |   o   o   | |    |        Kevin Sitze
   | |     >     | |    |        Wk. Phone #: 646-6206
   | |   \___/   | |    |
   | |___________| |    |     Internet E-Mail Address:
   |               |    |        ksitze%nmsu.edu
   |               |    |
   | Mac     ----- |    |     Physical Mail Location:
   |_______________|    |        Kevin Sitze
    |           = |     |        601 S. Melendres
    |_____________|     |        Las Cruces, NM  88005
                        |
----------------------------------------------------------------------