Many ActiveX objects (like those included into the DMForms library) can invoke events. For scripts embedded (or linked) into the HTML documents event handling never was a considerable problem - TWebBrowser control used in DM2003 Browser Window and HTML dialog boxes offers a lot of ways to respond the events fired from both embedded ActiveX controls and objects provided by the application. From the other hand, scripting events for objects created dynamically (that is, returned by CreateObject function in VBScript or new ActiveXObject statement in JScript) is not so straightforward because of the architectural features of COM-based event-handling mechanism and implementations of the script engines. As a result, there's no good way to hook up script to events for objects created at runtime.
Since almost any data acquisition application assumes asynchronous data exchange that relies upon events, you might think that it's impossible to host event-driven applications with additional hardware port controls by the DM2003 scripting action provider (scripter.dll unit). Hopefully, with Scripter Objects feature you can create such applications. Let's learn how.
In the example below we will use special DMTimer object to create simple event-driven script for scripter.dll action provider (you can also consider other invisible objects like DMComPort or DMClientSocket). To begin with, you should add your object to the list of "connectable objects". Use Provider Configuration dialog box available from New Action Dialog or just type
in the system Command Prompt window to bring up this dialog, then type in object name and ProgID and click Add button as shown at the screenshot:
Of course, you need to prepare user script that will interact with this object. Let's suppose that this script will allow user to start and stop timer, and display ticks count in the status line of DM2003 main window. Use Script Editor (or any other plain-text editor) to create following code:
dim Ticks Ticks=0 Timer.Interval=300 sub Timer_ontimer Ticks=Ticks+1 call Server.DisplayHint(Ticks) end sub '//////// TimerTest Action ///////// const TimerTest_Caption="Timer Test" const TimerTest_Hint="Enables or disables timer events" sub TimerTest_OnExecute Timer.InternalTrigger=not Timer.InternalTrigger end sub function TimerTest_OnUpdate if Timer.InternalTrigger then TimerTest_OnUpdate=dmuaVisible+dmuaEnabled+dmuaChecked else TimerTest_OnUpdate=dmuaVisible+dmuaEnabled end if end function
Save script to the disk and install appropriate user script file and action as described in User Action example and create a toolbar button (or menu item) for this action. When you click this button, you should see increasing Ticks value in the status line.