|
Article: Adding active
scripting support to Delphi applications
1. Why scripting?
Why do scripting abilities needed
in Delphi applications? There are many possible reasons.
- For example, we are developing
game. Many actors, many situations.
Scripting is the good (and maybe the only flexible enough)
way to let users (or addon developers) to:
- vary objects and actors properties, reactions, abilities
etc.;
- add new objects and characters;
- create new game scenarios
- Text processing
applications. Perl is the best langauge to work with texts:
search, replace, regular expressions. Perl can do much more
then Delphi with texts. So we can mix them and take the best
from both of them - why not? Write user interface in Delphi
and let script extensions (using Active Perl) to handle
texts.
- How to create plugin-based
application? There are copule of ways: DLLs (or BPLs),
COM... Why not scripting? Make some interface to read and
execute scripts in application, make specifications and go
ahead: application is open to extension using any active
scripts: VBScript, JScript, Perl, PHP, Rexx, Tcl... the only
requirement is that corresponding active script extension
must be installed in windows script host.
- Installers
are exactly those applications which need scripting
abilities...
- Any applications which must
be managed from outside. For example, some
application can consist of the set of all-sufficient objects
and scripts loaded from outer storage may trigger any
actions, change any parameters, allow/disallow any
functionality of apllication objects.
- Applications with variable
execution sequence.
- Etc, etc, etc...
2. What exactly is needed?
What are the basic requirements to
scripting engine mixed with Delphi application, in the most of
cases?
As practice shows, there is
well-defined set of abilities wich scripter "must
have", if it pretends to be universal scripting addon for
Delphi application:
- Support of most known
scripting languages. VBScript and JavaScript, Perl, PHP. May
be also Tcl, Rexx and other. In other words, any language
which is supported by Windows scripting host engine.
- Easy to integrate with Delphi
application.
- Ability to operate with Delphi
application objects, their properties, events and methods; deleting
and creating objects in script; passing object parameters to
script procedures and functions.
- Recognizing errors occured
during script execution.
- Quick and eminently qualified
support answering to any questions - they will appear
anyway, if you will be seriously engaged in scripting tasks
in your applications.
- Online help and manual
containing all most important questions.
- [ ] Add your ideas
here.
3. Is there any component
meeting these requirements?
Exactly! New version (2.0 is
up to date on May 19, 2003) of Delphi
script component named TekWSHControl (Windows
scripting host control for Delphi) from Ekas
Software is able to do everything described above,
and even more. Visit this scripter
component home page and learn more about it. Almost
all possible questions are coveraged there, and support
will quickly answer the rest if any.
4. What are basic TekWSHControl
advantages?
- Any script language supported
by Windows scripting host can be used for scripts: VBScript
and JavaScript by default, Perl, Python, Rexx, TCL, PHP,
XSLT and any other for which extensions are installed in
Windows.
- No need to implement
OLE-server functionality for application or any object to be
shared with scripting engine.
- Any object descending from
TPersistent can be added to script's namespace and operated
within script environment, including all of its published
members.
- Any object descending from
TComponent can be created within script and operated by
script or by application after script is finished.
- Recently used events of VCL
components can be handled by script procedures (and you can
add new events very easy if having source code of
TekWSHControl component).
- If control is added during
script executing (in script procedure), event handlers for
it are set automatically if any defined in script's body.
- If control exists
independently from scripts, event handlers for it may be set
just by one line of code (like "Panel1.OnClick:=
ekWSHControl1.OnClickHandler", and then event handling
is redirected to script's procedure "Sub
Panel1_OnClick()", if such present in scripts body).
- Native VCL code.
- Simplicity of use.
- Delphi 4, 5, 6 and 7 support.
Screenshots
| Online help
|