参考:http://delphi.mozdev.org/javascript_bridge/ Delphi / Kylix <-> SpiderMonkey Bridge
This sub-project provides a bridge between Delphi / Kylix and SpiderMonkey, the JavaScript engine from the Mozilla Foundation, allowing you to use it in your own applications. You can get the code via CVS or download an archive. If you encounter any problems, or would like to recommend a feature, please file a bug.
下载:
![]() | Download the source code archive. Or get the source via CVS. |
代码片断:
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- FEngine := TJSEngine.Create(40000);
- FEngine.StartDebugger;
- FEngine.Global.AddNativeObject(Edit1, 'edit');
- FEngine.Global.AddNativeObject(Button1, 'button');
- FEngine.Global.Evaluate('function toggle() { ' +
- ' edit.Visible = ! edit.Visible;' + // Toggle the visible property on/off
- ' button.Caption = (edit.Visible ? "Hide" : "Show");' + // Change button
- '}');
- end;
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- FEngine.Free;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- FEngine.Global.Evaluate('toggle()');
- end;