0

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.

Photo 1

But this code:

var s = 'rtfm'
s[0]

returns emptiness.

Photo 2

And also this check;

var s = 'rtfm'
s[0]==undefined

returns true.

Photo 3

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770

0 Answers0