[comp.sys.mac.hypercard] HC 2.0, XCMDs, THINK C, globals

brad@gobi.jpl.nasa.gov (Brad Pickering) (04/20/91)

I have some questions about how HC 2 handles XCMDs.  I would like to write
XCMDs that remember their globals between calls.  I tried this with a simple
XFCN that just added 1 to a global and returned the value as the result.
Each time it was called it came back with the next higher number.  But I tried
to do this with a more complex XCMD and I've be having lots of problems.
Does HyperCard jump to the beginning of the real resource or does it make a
copy and jump to the beginning of the copy?  If it is using the real resource
does it honor the purgable and locked attributes of the resource?  I tried
marking the resource as locked and it seemed to crash HyperCard.  If I use
global variables which are pointers to code or data within the XCMD don't want
HyperCard to move my resource around makeing the pointers invalid.

Any information about such problems would be appreciated.
--
--
Brad Pickering
brad@gobi.jpl.nasa.gov
--

Jim.Spencer@p510.f22.n282.z1.mn.org (Jim Spencer) (04/24/91)

Brad Pickering writes in a message to All

BP> I have some questions about how HC 2 handles XCMDs. I would like 
BP> to write XCMDs that remember their globals between calls. I tried 
BP> this with a simple XFCN that just added 1 to a global and returned 
BP> the value as the result. Each time it was called it came back 
BP> with the next higher number. But I tried to do this with a more 
BP> complex XCMD and I've be having lots of problems. Does HyperCard 
BP> jump to the beginning of the real resource or does it make a 
BP> copy and jump to the beginning of the copy? If it is using the 
BP> real resource does it honor the purgable and locked attributes 
BP> of the resource? I tried marking the resource as locked and it 
BP> seemed to crash HyperCard. If I use global variables which are 
BP> pointers to code or data within the XCMD don't want HyperCard 
BP> to move my resource around makeing the pointers invalid. 

HyperCard makes a copy of the external and then jumps to the beginning of it.  The solution to your problem is to create globals in your script and pass the values to the external (or read them in the external).  You should note that externals don't have globals per se.  There are mechanisms to in effect create these globals but they are not values off of HyperCard's A5 global space.
 

mandel@vax.anes.tulane.edu (Jeff E Mandel MD MS) (04/26/91)

In article <672472805.1@mmug.mn.org>, Jim.Spencer@p510.f22.n282.z1.mn.org (Jim Spencer) writes:
>
>Brad Pickering writes in a message to All
>
>BP> I have some questions about how HC 2 handles XCMDs. I would like 
>BP> to write XCMDs that remember their globals between calls. I tried 
>BP> this with a simple XFCN that just added 1 to a global and returned 
>BP> the value as the result. Each time it was called it came back 
>BP> with the next higher number. But I tried to do this with a more 
>BP> complex XCMD and I've be having lots of problems. Does HyperCard 
>BP> jump to the beginning of the real resource or does it make a 
>BP> copy and jump to the beginning of the copy? If it is using the 
>BP> real resource does it honor the purgable and locked attributes 
>BP> of the resource? I tried marking the resource as locked and it 
>BP> seemed to crash HyperCard. If I use global variables which are 
>BP> pointers to code or data within the XCMD don't want HyperCard 
>BP> to move my resource around makeing the pointers invalid. 
>
>HyperCard makes a copy of the external and then jumps to the beginning of it.  The solution to your problem is to create globals in your script and pass the values to the external (or read them in the external).  You should note that externals don't have globals per se.  There are mechanisms to in effect create these globals but they are not values off of HyperCard's A5 global space.
> 

The solution can be found in tech note 256. Basically, this describes the
creation of a private A5 world for you globals. The only hooker is that you
have to restore HyperCard's A5 world prior to any callbacks or kablooey. I have
an XCMD which I submitted to Info-Mac called SpinCursor (or maybe it was
CursorSpin) which uses this technique to get the MPW spinning beach ball
effect. If you can't find it on sumex-aim, I can mail or ftp it to you.


Jeff E Mandel MD MS
Asst. Professor of Anesthesiology
Tulane University School of Medicine
New Orleans, LA
mandel@vax.anes.tulane.edu