TEmbeddedWB.ExecScriptEx does not work with JavaScript

Place a TMemo , a TEmbeddedWB and a TButton in the Delphi VCL form.

This is the code from the form block:

 procedure TForm1.Button1Click(Sender: TObject); var vResult: OleVariant; Para1: string; begin Para1 := '5'; // edPara.Text; vResult := EmbeddedWB1.ExecScriptEx('evaluate', [Para1]); ShowMessage('Result from the Script: ' + IntToStr(vResult)); end; procedure TForm1.FormCreate(Sender: TObject); begin EmbeddedWB1.HTMLCode.Assign(Memo1.Lines); end; 

This is the contents of Memo1.Lines :

 <HTML> <HEAD> <TITLE>Test Script</TITLE> <SCRIPT> function evaluate(x) { alert("Hello from the script evaluate(x)"); return eval(x * x); } </SCRIPT> </HEAD> <BODY> TEST Script: eval(x * x)</BODY> </HTML> 

But this will not work: vResult = 0 after clicking the button.

Why is this not working?

+4
source share
1 answer

The parameter type passed to ExecScriptEx must be Integer in this case, not string :

 procedure TForm1.Button1Click(Sender: TObject); var vResult: OleVariant; Para1: string; ParaInt: Integer; begin //Para1 := '5'; // edPara.Text; ParaInt := 5; vResult := EmbeddedWB1.ExecScriptEx('evaluate', [ParaInt]); ShowMessage('Result from the Script: ' + IntToStr(vResult)); end; 

Now it works!

+3
source

All Articles