Problems with closeField

Jay Madren JaysLists at
Tue Sep 14 10:22:49 EDT 2004

Note the following from the docs on closeField:

"The closeField message is not sent when a handler changes the field's
contents using the put command.

If a field is closing and its contents have not changed, the exitField
message is sent instead of closeField."

As was mentioned earlier in this thread, since you are not passing the
"regular" keystrokes on to the engine, it never knows that the contents have
changed.  So it really is doing exactly what the docs say.  Note that if you
use any of the keystrokes that you are passing (backspace, Esc, return,
etc.) then the closeField message _is_ sent.  I never used HyperCard, but I
suppose that its engine somehow detected that the contents had changed even
if you didn't pass keyDown (maybe it does a post-compare like the exitField

As I understand it, from your original post, you're wanting to only run your
autocomplete code when actual "useable" keystrokes are entered.  If that's
the case, then you could just pass all keystrokes, without putting them into
the field yourself.  You can still act on keystrokes of interest using the
following variation:

local what

on keydown k
  if charToNum(k) is not among the words of "3 8 9 13 28 29 30 31" then
    put me into what
    --process autocomplete code here
  end if
  pass keyDown
end keydown

on closefield
  put "Field changed: Field=" & fld "Field1" & ", what=" & what
end closefield

But there is a problem with this method.  The "what" variable doesn't get
the last keystroke entered until the keyDown is passed (as you can see in
the output on closeField).  I think this is because the field's contents
doesn't get updated until the engine receives the keystroke.  So, the
following will fix that:

on keydown k
  if charToNum(k) is not among the words of "3 8 9 13 28 29 30 31" then
    put me into what
    put k after what
    --process autocomplete code here
  end if
  pass keyDown
end keydown

Hope this helps,
Jay Madren

-----Original Message-----
From: use-revolution-bounces at
[mailto:use-revolution-bounces at]On Behalf Of
JonathanC at
Sent: Tuesday, September 14, 2004 07:40
To: use-revolution at
Subject: Re: Problems with closeField

Dear Wilhelm,

Thank you very much for replying (and especially for making sure I SAW
your reply, since the Digest mixed up my post).

I, too, had since worked out an exitField version. However, yours is more
elegant than mine: e.g. using a 'script local variable' rather than a
global variable. :-)

What I still don't understand (and perhaps you don't either, given your
comment "This is contrary to what you would expect from the docs") is why
the field doesn't send a closeField when the contents of the field have

Here's the problem, again, in its simplest form:

Create a field with the following script:

on openField
  put empty
end openField

on keydown k
  if charToNum(k) is among the words of "3 8 9 13 28 29 30 31"
    then pass keyDown
  put k into selection
end keydown

on closefield
  put "Field changed."
end closefield

Typing into the field produces completely normal behaviour: arrowkeys, the
deletekey and backspace key are passed, and everything else is handled by
the line "put k into selection". But when you click out of the field, NO
closeField message is sent.

Now delete (or comment out) the keyDown handler. Type into the field and
click out of it: The message box reports (correctly) that the field has

Since HyperCard sends closeField in both situations, I gather that
Revolution must have its own definition of 'closeField'.
Can anyone from RunRev (or with inside knowledge) confirm this?


Jonathan Cooper
Manager of Information / Website
Art Gallery of New South Wales
Sydney, Australia

More information about the use-livecode mailing list