Is there some way to run Javascritpt in Delphi using Elements as Compiler?

Hi

I’ve seen some scratch of this solution, but I didn’t find any doc related.

Is possible to run ECMAScript (Javascritpt) in Delphi using Elements as Compiler and Hydra as bridge?

Thank you.

Since Elements does not support JavaScript as a language to begin with:, no ;). Also, to use the Elements compiler in your app, yo’d need a deployment license for that, or every user of your app would need an Elements license ;).

That said, you should be able to host the .NET-based RemObjects Script for .NET | RemObjects Software in your Delphi app, using Hydra, if you create a .NET plugin (which you could do in Oxygene).

I’ve tried to running the sample, found on github, but it was an unsuccessful test.

Is there some updated sample?

Thx

Not really, but also Scriopt hasn’t changed in a long time. What fails with he sample?

Some Javascript basic funcion, like Alert etc…

I don’t know what exactly group of commands the interpreter run.

Okay. Some concrete steps would be appreciated som I can have someone have a look at this; otherwise it’s always a bit of a wild goose chase :wink:

Follow a C# example found in github.

This object is responsible for run the script

private RemObjects.Script.EcmaScriptComponent ScriptEngine;

Debugger.zip (628.6 KB)

Okay. I’ll have a check tomorrow, when i’m on Windows.

My apologies for the delay. What exact problem should I be looking out for? ran the DXebugger sample, and it seems to work fine. What script code are you running, and what misbehaves, exactly?

Note that alert() is a function provided by the web-browser, not JavaScript. You need to make that distinction. Script supports whatever APIs you define in your app to expose to it.

ah I think there’s some misunderstanding. Script provides the core ecmascript 5 functionality.

Alert (and anything else defined on Window): Window.alert() - Web APIs | MDN is not part of that. Script provides a fully sandboxed Javascript engine, and out of the box no functionality to interact with the user directly (that’s on purpose). That said it’s really easy to add. Something like:

ScriptEngine.Globals.SetVariable("alert", (MyDelegate)((object[] args) => 
{
  MessageBox.Show(string.Join(" ", args.Select(e => e?.ToString() ?? ""));
}));

Would probably already give the functionality you want (typed from memory)

2 Likes

This worked, thank you.

2 Likes