Scripting Dynamic Callbacks

Is this possible?

I'm playing around with scripting objects. I have a COM control "myControl" that has a method "subscribe" to create an asynchronous subscriber of messages:



myControl.subscribe "params"



This control actually creates a callback called
4,921 views 5 replies
Reply #1 Top
Anyone have any ideas on this? I know the COM component is working because I can publish messages from DX3 and see them in other applications but whatever I try I just can't get the myControl_newMessage callback to fire. If I can get this to work then I can upgrade to DX Pro and start cranking out Gadgets...

Nick
Reply #2 Top
Have a look into the WithEvents statement. Not sure if it helps, but it was all I could think of right now.
Reply #3 Top
Unfortunately WithEvents is not supported in VBScript. I'm wondering if JScript will help. Either that or I might have to write a plugin which seems like an awful lot of trouble to go to. It just seems a shame - Stardock have given us the ability to embed ActiveX controls but that support is very limited if we cannot consume their events.

Nick
Reply #4 Top
How are you registering the callback ?
Here is an example of a callback function that works.
The interesting peice is setting the call back function
http.onreadystatechange=GetRef("processMsg")

Hope this helps

Dim http
'Called when the script is executed
Sub Object_OnScriptEnter
getNewMessage()
MsgBox("done on enter")

End Sub
'Called when the script is terminated
Sub Object_OnScriptExit
On Error Resume Next
http.abort
Set http = Null
End Sub

Function getNewMessage()
Set http = createObject("microsoft.xmlhttp")
http.onreadystatechange=GetRef("processMsg")
http.Open "GET","http://www.w3schools.com/xml/note.xml",True
http.Send
End Function

Function processMsg()
If http.readyState=2 Then
MsgBox("http request started")
End If
If http.readyState=4 Then
MsgBox("http response complete")
End If
End Function
Reply #5 Top
Thanks for the reply. Unfortunately the component in question does not supply a property equivalent to onreadystatechange. The documentation just states:

# Declare a variable for the listener.
Dim WithEvents myListener as TibrvListener

This declaration triggers VB to automatically define a private subroutine callback stub named myListener_OnMsg. The program must complete this method stub for each listener object.

Nick