[comp.sys.mac.hypercard] AppleEvent limitation in HC 2.1?

mpradhan@f.adelaide.edu.au (06/12/91)

 On the weekend I was playing with HC 2.1 and Macintosh Common Lisp (MCL)
 v2.0b1p2, using AppleEvents to communicate between them.

 I wrote some stuff in MCL to allow it to handle the send ('dosc') and
 request ('eval') AppleEvents from HyperCard, as well as to send the
 same AEs from lisp to HC.

 Everything works very nicely, except I have run into a problem which
 may be a limitation of HC: when sending a 'dosc' or 'eval' AE to HC from
 MCL I have found that HC will not accept more than 255 characters, if
 the AE contains more than 255 chars HC ignores it altogether! If, however,
 HC requests data from lisp then it happily grabs over 255 chars of data.

 For example if HC requests the result of (factorial 160) it will happily
 accept the 300 or so characters of the number which is the result. I
 can't get HC to accept the result from MCL if it sends a 'dosc' AE, it
 will only accept up to factorial 154 which is a number of about 253 or
 so characters (digits).

 Is this a set limitation of HC?

 Thanks in advance for words of wisdom.

 Regards,
 Malcolm
_________________________________________________________________
    Malcolm Pradhan
    Medical Computing, Faculty of Medicine        _--_|\
    University of Adelaide, South Australia      /      \
    InterNet: mpradhan@f.adelaide.edu.au         \_.--._/
    Fax: + 618 338 2108                                v

jkc@Apple.COM (John Kevin Calhoun) (06/12/91)

In article <1991Jun12.154845.1@f.adelaide.edu.au> mpradhan@f.adelaide.edu.au
(Malcolm Pradhan) writes:
>
> On the weekend I was playing with HC 2.1 and Macintosh Common Lisp (MCL)
> v2.0b1p2, using AppleEvents to communicate between them.
>
> Everything works very nicely, except I have run into a problem which
> may be a limitation of HC: when sending a 'dosc' or 'eval' AE to HC from
> MCL I have found that HC will not accept more than 255 characters, if
> the AE contains more than 255 chars HC ignores it altogether!
>
> Is this a set limitation of HC?

When receiving an 'eval' event, HyperCard can handle expressions only up
to 255 characters in length.  In fact, HyperCard is doing the same thing
that it does when an XCMD invokes the EvalExpr callback.

However, when receiving a 'dosc' event, HyperCard can handle a script as
long as 30000 characters.  Sending this event to HyperCard is similar to
invoking the RunXHandler callback from an XCMD.

In addition to these limitations, there is one more, which I hope will be
removed in a future release.  When HyperCard receives an Apple event
parameter of type 'list', it attempts to coerce it to text for use in
HyperTalk.  Unfortunately, the coercion handler limits the textual form
of each item in the list to 255 characters.  This is fine for the 'odoc'
and 'pdoc' events, which contain lists of alias records as parameters, but
it's not so good in other cases.  If you're sending Apple events to
HyperCard with parameters of type 'list', and the items in the list can
be longer than 255 characters, there are two things you can do:

  1)  convert the parameter to text before sending it to HyperCard.
  2)  override HyperCard's built-in 'list' to 'TEXT' coercion handler
      with a better one.
  
The 'dosc' event, as described in the Apple Event Registry, shouldn't use
a parameter of type 'list'.  It should send the script to be executed in a
parameter of type 'TEXT', or it should send an alias record that resolves
to a script file (HC doesn't have script files, and so doesn't support
this), or it should send an object specifier that resolves to the script to
execute (HC 2.1 doesn't support Apple event objects, so this won't work
either at present).

Hope this helps.

Kevin Calhoun
jkc@apple.com

jkc@Apple.COM (John Kevin Calhoun) (06/13/91)

Dr. Pradhan and I exchanged a couple of e-mail messages, and we
finally figured out what the problem was.  He was sending HyperCard
a line of HyperTalk like the following:

     put "<string over 250 characters long>" into field x

I don't know why I didn't remember this before -- HyperTalk can't
handle single lines longer than 255 characters!  Therefore the
line above won't work, whether you try to execute it locally or
send it to HyperCard in a "do script" event.

Because of this limitation, neither the "do script" event nor the
"evaluate expression" event is a good way to send large chunks of
data to HyperCard.  I suggested that he define an Apple event for
setting the contents of a field, class "WILD" and id "SFLD", like so:

  on appleEvent class,id,sender
    if class & id is "WILDSFLD" then  -- class = "WILD", id = "SFLD"
      request appleEvent data  -- direct parameter contains field number
      put it into fieldNum
      request appleEvent data of type 'STUF'  -- contains text for field
      put it into theStuff
      if there is a field fieldNum
      then put theStuff into field fieldNum
      else reply error "No such field"
    else pass appleEvent
  end appleEvent

You can make this event a great deal fancier -- specifying whether the
field is a card or background field, specifying it by name, number, or
id, specifying even the card and stack to which it belongs.            

In the future, when HyperCard supports the Apple event object model
and the core suite of Apple events, you would probably use the standard
"set data" event instead of a made-up one like "SFLD".  But in the
meantime, you're free to define and use Apple events for your own
purposes and to tell HyperCard how to handle them by writing appleEvent
handlers.

Kevin Calhoun
jkc@apple.com