Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sinking Events in JScript

29 views
Skip to first unread message

Ryan Tomayko

unread,
Apr 11, 1999, 3:00:00 AM4/11/99
to
I'm working on a scripting host that relies heavily on events. I have
sucessfully added my interfaces and coded GetItemInfo to be ITypeInfo ready.

Using VBScript I can sink the events perfect using
"Sub Obj_Event()" syntax. The Engine Queries GetItemInfo with the
SCRIPTINFO_ITYPEINFO flag and everything is well. However I can not get
events sunk in JScript. After researching for a while, I found a kb article
explaining that Obj_Event syntax was ripped out in version 3.0 of JScript.
So, I tried

obj.event = obj_event ;
AND
obj.event ="obj_event()";

IE style, and I get an "Object doesn't support this property or method." In
the Knowledge base article it says that events should be sunk in the <SCRIPT
FOR="obj" EVENT="event"> syntax. Obviously this is not a possibility in
non-browser hosts.

So, how do you sink events in JScript without a web browser? The only thing
I can think of is to implement some kind of script aware interface, in each
class, that actual calls the functions through the IActiveScript's
IDispatch. What a bunch of bull. Can someone please shed some light on an
efficient(perhaps built-in) method of sinking events using JScript? I'd
really like to enable IE style assignment, but have no clue how they're
doing it.

btw, I'm using the JScript 5.0 Engine.


Thanks,
Ryan


Eric Lippert (Microsoft Scripting Dev)

unread,
Apr 12, 1999, 3:00:00 AM4/12/99
to
Hey Ryan,

You are correct, the "object.onevent" syntax is a property of the _object_,
not the script engine. IE's objects simply have properties which are set to
the functions which should be called when the event is fired -- rather than
the traditional COM connection points, the script code itself informs the
object what it should do when the event goes.

Obviously you can't do this to an arbitrary object unless you have the
source code and choose to rewrite it to have all those extra properties.

To get the VBScript-style implicit event handling in JScript, use :: instead
of _. For instance:

function button1::onclick()
{
// whatever
}

Note that this only works if the JScript engine has been put into CONNECTED
state. This syntax doesn't work in IE because IE doesn't put the JS engine
into connected state. (The IE team did not want to support an event binding
syntax different from Navigator's syntax, for better compatibility.)

Eric

Ryan Tomayko <ry...@neo.rr.com> wrote in message
news:#9TtD29g#GA....@cppssbbsa02.microsoft.com...

Eric Lippert (Microsoft Scripting Dev)

unread,
Apr 12, 1999, 3:00:00 AM4/12/99
to
Yes, if JScript is attempting to sink events of a dispatch object then
JScript QI's the source for IBindEventHandler. If the source supports IBEH,
then it just binds the handler, end of story. If the source does not
support IBEH, then we do the normal COM thing -- create an event sink
object, advise the connection points, etc, etc.

Eric

Andrew Nosenko <cap...@meadroid.com> wrote in message
news:er7oOvSh#GA.262@cppssbbsa03...
> Hi Eric,
>
> As far as I may guess, IBindEventHandler is behind the following IE-style
event
> binding schema:
> <script>
> function window.onload() { alert("Loaded!" }
> </script>
> JScript does QI for IBindEventHandler on 'window', right?
>
> Thanks,
> Andrew Nosenko.
>
>
> Eric Lippert (Microsoft Scripting Dev) <Eri...@Microsoft.com> wrote in
message
> news:OY2o2ORh#GA....@cppssbbsa02.microsoft.com...

Andrew Nosenko

unread,
Apr 13, 1999, 3:00:00 AM4/13/99
to
0 new messages