I need to execute a JS script in a Delphi program.
There is a problem that bothers me.
I put js: OleVariant;
into Form1's public
section, and then use this code:
procedure TForm1.FormCreate(Sender: TObject);
begin
js := CreateOleObject('ScriptControl');
js.Language := 'JScript';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Memo4.Text := js.Eval(Memo3.Text);
end;
After that, this JS code works normal:
var s = 'rtfm'
s.slice(0,1)
it returns r
.
But this code:
var s = 'rtfm'
s[0]
returns emptiness.
And also this check;
var s = 'rtfm'
s[0]==undefined
returns true.
A similar situation is observed with the absence of a JSON object, so I could not execute JSON.parse
. But I found this code, and this again allowed me to use JSON after its execution.