Scripter Objects

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.

Standard script engines (both VBScript and JavaScript) supports "named" objects as well as so-called "automagic" event binding. In combination, these features allow us to add arbitrary ActiveX objects into the namespace of script engine at the provider initialization stage, when script code is compiled and engine goes to "connected" state. The procedures and functions whose names satisfy naming conventions (Object_Eventname for VBScript and Object::Eventname for JScript) are automatically assigned to the events of appropriate objects. For example, DMInternalApplication object exposed to the scripts through Server variable with full event support (the most of application events handled in the default masterscript.vbs).

How to use Scripter Objects?

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
rundll32.exe Scripter.dll,ShowConfigurationDialog
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:

Add connectable scripter object

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


sub Timer_ontimer
  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
  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.