Put a TMemo, a TEmbeddedWB and a TButton on a Delphi VCL form.
This is the code from the form unit:
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 content of the 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 it does not work: vResult is 0 after clicking the button.
Why it does not work?
The parameter type passed to
ExecScriptExmust be anIntegerin this case, not astring:Now it works!