ActiveX scripting is a key technology in the
Data Master 2003. This software utilizes scripts to implement its standard
functionality as well as to add new user-defined features. In fact,
a simple mathematical operation or data
acquisition application requires several dozens of lines of
easy-to-understand VB code and may be created in hours even if you are not a
professional programmer. At once, this technology has virtually no restrictions.
With additional ActiveX controls accessed from scripts your application may be
as complex as you need. DM2003 software supports standard language engines
preinstalled with any copy of Windows operating system or Internet Explorer
browser.
Features based on scripting technology:
Scripter.DLL - default Action Provider
that implements almost all standard features of DM2003 application. Generally
speaking, each menu item or toolbar button in DM2003 is linked to the
invisible Action object. This object has several attributes - ID, Caption,
Hint and two methods - Execute and Update. Execute method is called when user
activates appropriate control (e.g. selects menu item or clicks the button).
Update method is called periodically (in the application's message processing
cycle) to set correct item state, for example, to enable/disable linked
controls when operation is not possible. The scripter.dll unit maintains
extendable list of action objects, by associating
several specially named language elements (variable and function definitions)
with every action.
At DM2003 startup, scripter.dll unit compiles master script file (with
standard actions definitions) and installed user scripts and builds action
list. Users may easily add new actions: just create and install new user
script file and action object (s) as described in the example
below (both master script and user scripts must be written in the same language). If you
need to change standard actions behavior, edit master script file.
Keep in mind that scripter.dll unit supports application event handlers and
additionally compiles all definitions from both DM and
DMForms type libraries, so that you can use symbolic
constant names in your scripts. Besides, you can use its Connectable Objects feature - namely, create
specially defined ActiveX objects that can be bound to the event handlers in
your script code (ones created by CreateObject() function can't).
DMInternalApplication object is
available through predefined Server variable.
Browser Window and HTML Dialogs - are
containers for user-defined HTML with embedded scripts. HTML used in the
DM2003 to define customizable user interface for various operations
implemented by the script code. Unlike usual web pages on the internet sites,
you open HTML documents for DM2003 into specialized instances of MSIE (TWebBrowser
control) that have full access to the DM2003 object model.
For Browser Window, reference to the
DMInternalApplication object is
available via window.external property.
Events are also supported, so that your
applications can be more interactive, for example, you may process plot point
clicks and so on.
HTML Dialog boxes may be displayed using
IDMApplication2.ShowDialog method. Scripts in dialog box HTML should
access DMInternalApplication object
using window.external.Server property. You also may use
window.external.Close method to close dialog box programmatically
(typically in OkButton_onclick event handler) and window.external.Arguments
property to obtain read/write access to the dialog box arguments. Modeless
dialog boxes implement additional property - window.external.IsVisible
that allows you to hide or show dialog window. For modeless dialog boxes,
ShowDialog method returns reference to the TWebBrowser object, thus you have
full access to the contents of the HTML document. Events are also supported.
In addition, you may use any ActiveX controls to add custom functionality to
your HTML application. This may be specialized user interface controls,
hardware drivers or any other API wrapped into ActiveX/COM interface. A number
of useful ActiveX controls (dmforms.ocx unit)
installed with the DM2003 software package.
Script Editor - allows you to
edit, compile and run scripts. Use it to debug scripts or automate single use
tasks, when you don't wish to make special menu item or toolbar button. In
addition, you may explore DM2003 object model and dispatch objects.
Notice that you also may use professional script debuggers (free stand-alone
Microsoft Script Debugger or Microsoft Script Editor bundled with the Microsoft Office
and Microsoft Visual Studio) to edit and debug scripts and HTML documents running into
DM2003 process. This is a feature of the TWebBrowser control and script engines.
VBScript or JavaScript?
Frankly speaking, this paragraph should be titled "Why VBScript?". Although
two standard language engines, namely vbscript.dll and jscript.dll are
installed on any Windows system, in fact, DM2003 uses VBScript as a primary
scripting language. There's a nice article on the MSDN that discusses advantages
and shortcomings of every language. In particular for DM2003, following VBScript
features tip the scales:
More straightforward syntax, very popular between engineers and scientists
More powerful (error handling, "ByRef" (output) parameters, "true" binary
arrays)
More suitable for arbitrary objects (JavaScript is targeted at the web
browsers)
1. Use Help|Wizards|Action Wizard in the Script Editor
to create following code:
'//////// MyTestAction Action /////////
const MyTestAction_Caption="My Test Action"
const MyTestAction_Hint="Displays active document caption"
sub MyTestAction_OnExecute
'<put sub body here>
MsgBox Server.ActiveDocument.WindowCaption
end sub
function MyTestAction_OnUpdate
MyTestAction_OnUpdate=dmuaVisible '<-modify this code
if Server.DocumentCount>0 then
MyTestAction_OnUpdate=dmuaVisible+dmuaEnabled
end if
end function
3. Select "HTML/Scripting action provider" and click "Configure selected
provider" button. On the "User Files" tab, click "Add" button
and select script file. Click "OK" to save changes.
4. Restart DM2003 and bring up New Action dialog box again.
Select "HTML/Scripting action provider" and select MYTESTACTION action from the list
of Action IDs. You may also set image and category. Click "OK" to add new action.
5. Drag "My Test Action" from the list of actions ("Actions" tab)
onto the toolbar or menu and close dialog.
That's all job! If you made no errors, new menu item (or toolbar button) will
display caption of active data window or will be disabled if there's no data windows.
What to do if there's errors in the script file and you see script compilation
error message at startup? You can't remove this file until you load into DM2003!
Just rename or move the file - if DM2003 couldn't find it, it will be ignored.