Delphi 与 JavaScrpt 交互[1]
准备一段js放置于Memo1中
function bb(cc){ var d = cc+5; return d; }
实现代码:
uses ComObj;
function ExecScript(Code,Lang,Func:string):string;
var
script:OleVariant;
begin
try
script:=CreateOleObject('ScriptControl');
script.Language:=Lang;
script.AddCode(Code);
Result:=script.Eval(Func);
except
end;
//按钮事件
procedure TForm1.BitBtn2Click(Sender: TObject);
var
bb:string;
begin
bb:=ExecScript(Memo1.Text,'JavaScript','bb(3)');
ShowMessage(bb); //8
end;
创建时间:2021.06.18 更新时间: