Thoughts on script events

Posted by Shadowfyr on Sat 03 Jan 2004 06:37 PM — 4 posts, 11,954 views.

USA #0
While banging my head against the wall again over this annoyance, it occured to me that there may be a possible solution, though I am unsure if it could work.. The obvious first question is, "If something else creates an object, can your own code recieve events from it?"

Now why is this a meaningful question? Because instead of implementing a full on handler for dealing with objects, and this making CreateObject or New on the script useless. It occured to me that you may be able to make a command like:

DriveEvents (Long ObjectHnl, BSTR ObjectName)

This bit of code would read the information for the object, looking for events. If for instance the object had an Image, an OK button and a Cancel button (and the object had events for them), then the code would create event names: ObjectName_OnClickImage, ObjectName_OnClickOK and ObjectName_OnClickCancel. As long as the guy making a plugin for Mushclient remembered to include a DriveEvent command for the ActiveX program he was using, the event driving code would automatically look for the correct subs to call when they happened.

Anyway, this is my working theory and it is slightly less potentially bloating that a complete object handler that had to intecept every property, function call, etc. for the object, not to mention handling its creation and destruction. There has to be some easy solution to this annoyance... :p
Australia Forum Administrator #1
Ah, I don't see how this would work. :(
USA #2
Sigh.. Yeah. It would involve accessing the controls internal event list and generating a set of names from that. I am looking for code to do this for something of mine too, but it is one of those annoying damn things that no one seems to bloody document in any sane fashion, because only form designers, IE, HTML editors and a handful of other programs even actually need the feature. Even then most of them cheat anyway and only provide a known set of controls, for which they already know the events and can impliment specific code to handle. This requires trapping 'unknown' events and correctly matching them to the events listed in the control in some fashion.

Can it be done? *yes*. Done easilly or there even being a snowballs chance in a blast furnace of finding documentation on it, apparently not likely. :(
Amended on Tue 24 Feb 2004 11:00 PM by Shadowfyr
USA #3
Hmm. Ok, I just did a test with:

Private WithEvents UpDwn As VBControlExtender

Private Sub Form_Load()
  Licenses.Add "MSComctl2.UpDown", "651A8940-87C5-11d1-8BE3-0000F8754DA1"
  Set UpDwn = Form1.Controls.Add("MSComctl2.UpDown", "upd1")
  UpDwn.Move 500, 500, 300, 300
  UpDwn.Visible = True
  UpDwn.object.Max = 35
End Sub

Private Sub UpDwn_ObjectEvent(Info As EventInfo)
  Debug.Print Info.Name
  Dim param As EventParameter
  For Each param In Info.EventParameters
    Debug.Print param.Name; param.Value
  Next
End Sub

Private Sub UpDwn_GotFocus()
  Debug.Print UpDwn.object.Value
End Sub

The Info.Name produced by clicking the down arrow is DownClick, the up arrow is UpClick, etc. This means that if you can capture the events in Mushclient itself, by adding it to an internal collection and associating it with a name, then you should be able to generate a call to a sub with a similar name to the event. So:

set Winamp = createobject("Winamp.COM")
DriveEvents (Winamp, "Winamp")

And in Mushclient an event fired by the control would produce:

Info.Name = "SongChange"
Control.Name = "Winamp"

and thus call the 'Winamp_SongChange' sub in the script.

Easier than I thought.. Actually much easier than knowing the events before hand. Of course I have no idea how you call named subs in the script from the client, but it should be possible to call a new on created this way.