[comp.sys.mac.hypercard] XCMD help needed

beamlab@hscfvax.harvard.edu (D.McCallie) (02/18/88)

I need some hyperAdvice:
	Is it possible to write an XCMD that remembers (internally)
data between invocations ? In other words, can I have states associated
with an XCMD so that the first call is treated differently from
subsequent calls ?
	A similer question: is it possible to have external global
data that is shared between separate XCMDs, or must I send such
info back to HC itself (and thus require the stack author to
create stack "global" variables.
	My preferred programming environment is LSC, but solutions
in any language would be appreciated. Thanks.

	David McCallie
	Children's Hospital
	...harvard!hscfvax!{dpm, beamlab}
	dpm@hscfvax.harvard.edu

edmoy@violet.berkeley.edu (02/22/88)

In article <515@hscfvax.harvard.edu> beamlab@hscfvax.UUCP (850103@D.McCallie) writes:
>	Is it possible to write an XCMD that remembers (internally)
>data between invocations ? In other words, can I have states associated
>with an XCMD so that the first call is treated differently from
>subsequent calls ?

I haven't tried it yet, but if you create a resource (say of type 'DATA') in
the stack, then you could do a GetResource() every time your XCMD is called.
By making it nonpurgeable, the data would remain intacted.  The latest state
of the resource could be saved permenently by calling ChangedResource().

>	A similer question: is it possible to have external global
>data that is shared between separate XCMDs, or must I send such
>info back to HC itself (and thus require the stack author to
>create stack "global" variables.

If the XCMDs shared the same knowledge of the resource, then the resource
can be used to pass global info.

Edward Moy
Workstation Software Support Group
University of California
Berkeley, CA  94720

edmoy@violet.Berkeley.EDU
ucbvax!violet!edmoy

ephraim@think.COM (ephraim vishniac) (02/22/88)

In article <515@hscfvax.harvard.edu> beamlab@hscfvax.UUCP (850103@D.McCallie) writes:
>	Is it possible to write an XCMD that remembers (internally)
>data between invocations ? In other words, can I have states associated
>with an XCMD so that the first call is treated differently from
>subsequent calls ?
>	A similer question: is it possible to have external global
>data that is shared between separate XCMDs, or must I send such
>info back to HC itself (and thus require the stack author to
>create stack "global" variables.

>	David McCallie
>	Children's Hospital
>	...harvard!hscfvax!{dpm, beamlab}
>	dpm@hscfvax.harvard.edu

What I would do is to use resources.  (Be warned that I use resources
for every blessed thing, however.)  When your XCMD is invoked, do a
GetNamedResource to find your data resource.  Use a name for which
collisions are very unlikely.  Your own name, for example.  If you
don't find it, this must be the first call, so create the resource
using a new resource ID.  (There's a trap that spits out unused
resource ID's for a given type, but I don't recall the name off the
top of my head.)

Any number of XCMD's can share data in this way: they just have to
agree on the name and format of their common data resource.  You can
even save your data across HyperCard runs by marking the resource
modified and making sure it gets saved as part of the stack.


Ephraim Vishniac					  ephraim@think.com
Thinking Machines Corporation / 245 First Street / Cambridge, MA 02142-1214