Sending keyDown
Jim Ault
jimaultwins at yahoo.com
Mon Oct 26 11:26:05 EDT 2009
On Oct 21, 2009, at 2:43 PM, DunbarX at aol.com wrote:
> Just when I was thinking I had the differences between HC and Rev
> down, I
> stumble.
>
> I have an editable field with this handler:
>
> on keyDown var
> send "keydown" && var to this stack
> put var
> end keyDown
>
> In HC, any text I type gets placed into the field, so typing works
> normally, but then I can do stuff with the last char, like put it
> into the msg box.
> Actually, in HC, I say "to Hypercard", but it makes no difference.
>
> But in Rev I get an error message stating that Rev "can't find
> handler near
> "keyDown".
>
> Can't wait to see where this divergence between the two lies...
To me it does not make sense to send the keyDown to the stack script.
If it *did* work, you would be telling the engine to send a typed
character to the stack object, not a field object.
If the keydown occurs in a field, then it can be trapped, steps taken,
then the pass command used.
From the docs for the 'pass' command
Important! You cannot use the pass command to pass a message that
was originally sent with the send command.
SEND documentation
The object is any object reference.
If you don't specify an object,
the message is set to the object whose handler contains the send
command.
If you specify a time, you must also specify an object.
-----
Thus, the compiler will check to see if there is a handler that
matches the 'send' message in an object.
I don't think Revolution is an object.
-----
DISPATCH documentation
If no target is specified, the message is sent to 'me'.
Note that in the context of a behavior, this will typically be the
child that is executing rather than the behavior object itself.
The dispatch has capability beyond the 'send' command in order to test
the result of the passing of the message.
"handled" - the message was handled and not passed
"unhandled" - no matching handlers were found
"passed" - the message was handled but passed by all handlers
-----
Thus, the compiler will not check to see if there is a handler that
matches the 'send' message in an object.
This is consistent with behaviours that get used by zero to many
objects.
These objects may legally created during script execution.
This is consistent with object oriented programming and classes where
objects may not exist at compile time.
The 'send' command is tested for a matching handler at compile time.
field script ----------
on keyDown var
send "keydown" && var to this stack
-- the send changes the target definition to 'this stack'
end keyDown
stack script ---------
on keyDown var
pass keyDown --only works if passed from a field so the target is
still defined
end keyDown
From the docs for the 'pass' command
If you use the pass...to top form of the pass control structure, the
message is passed directly to the engine, without being passed through
any other object in the message path.
Changes to Revolution:
The pass...to top form was added in version 2.1.
Hope this clarifies a few things for you.
Jim Ault
Las Vegas
More information about the use-livecode
mailing list