What Does The Bridge Do? The bridge connects an application written in Delphi with scriptability. Why Use This Bridge? or What Is So Great About SpiderMonkey? Let me first acknowledge the other great scripting products out there. Products such as Innerfuse Pascal Script III by Carlo Kok; PaxScript by Alexander Baranovsky (which supports multiple scripting languages); Delphi Web Script, and others.
The reason SpiderMonkey is a good choice is due to its stability. It is the oldest, most heavily tuned engine available. It is also supported by dozens of engineers in the open source community. Mozilla releases new versions of the engine regularly which improve speed, reliability, and conformability to the ECMA-262 Edition 3 standard. Is The Delphi Code Stable? This is, of course, use-at-your-own-risk code, but before each public release I test the code using a performance tuner and memory leak evaluator. I make every effort to eliminate memory leaks. Unfortunately I can't certify the code or provide any guarantees as to its reliability. I can only tell you that I would use each release in my own applications. What Classes Are Available And How Do They Help Me? There are several classes included in this package, designed to integrate Delphi and SpiderMonkey as tightly as possible. These are:
- TJSEngine
All scripting interactivity begins with this component. All of the other classes depend on this. If your application is multithreaded, you'll create a new instance of
TJSEngine
for each thread.
- TJSScript
This class provides methods for compilation, execution, serialization, and deserialization of JavaScript code. Methods are also available for loading, saving, and streaming both raw and compiled code.
- TJSBridge
This class is intended to extend existing
TObject
descendents (or classes with no explicit inheritance) with instant script interactivity. Declare any Delphi object as a descendent ofTJSBridge
, then publish all the properties and methods you want scriptable, and then connect it to aTJSEngine
.
- TJSObject
Most of your Delphi-to-script code will deal with
TJSObject
's. These essentially expose JavaScript objects to Delphi code. From here you can call functions, evaluate object-scope code, get and set properties, etc.
- TJSString
This creates a string that is interactive with both Delphi and script. Any change to the string will be reflected in the other codespace.
- TJSInteger
This creates an integer that is interactive with both Delphi and script. Any changes to this integer are reflected in the other codespace.
- TJSDouble
Exactly like
TJSInteger
, except as a floating point number.
- TJSBoolean
Exactly like
TJSInteger
, but now the value is a boolean.
- TJSArray
This class is still in the beta stage -- it isn't quite there yet. If you can help stabilize it, then please do so. In the meantime, play with it, but don't depend your application on it.
- TJSFunction
I'm putting this class at the end because it's kinda flaky. A
TJSFunction
is not retrievable when it goes out of scope. You may create one, but theTJSFunction
instance can not be recovered by another scope. The good news is your function will not disappear -- it remains callable from the scope you specified, it's only theTJSFunction
instance that gets "lost".
MSVCR70.DLL
and JS3215R.DLL
in your Windows' Search Path or the directory where your application is run. Linux users will need libjs.so
in their path or their application directory. To use the classes in a unit, you need to include jsintf
in the uses
clause. See the documentation on the bridge classes to understand what's available. Start with TJSEngine
, the central component of your JavaScript interaction.