delphi执行js


本文整理自网络,侵删。

 

命名空间:ComObj

 

[delphi] view plain copy

unit Unit1;  

  

interface  

  

uses  

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  

  Dialogs, StdCtrls,ComObj;  

  

type  

  TForm1 = class(TForm)  

    btn1: TButton;  

    mmo1: TMemo;  

    lbl1: TLabel;  

    edt1: TEdit;  

    procedure btn1Click(Sender: TObject);  

  private  

    { Private declarations }  

  public  

    { Public declarations }  

    function ExecJs(Code,Func:string):string;  

  end;  

  

var  

  Form1: TForm1;  

  

implementation  

  

{$R *.dfm}  

  

function  TForm1.ExecJs(Code,Func:string):string;  

var script:OleVariant;  

begin  

  script:=CreateOleObject('ScriptControl');  

  script.Language:='JavaScript';  

  script.ExecuteStatement(Code);  

  Result:=script.Eval(Func);  

end;  

  

procedure TForm1.btn1Click(Sender: TObject);  

var ss:string;  

begin  

  ss:=ExecJs(mmo1.Text,Trim(StringReplace(edt1.Text,'()','',[]))+'()');  

  ShowMessage(ss);  

end;  

  

end.  


相关阅读 >>

Delphi程序常用的公共代码

Delphi tooltip提示窗口单元

Delphi 判断时间是否是下午 dateutils.ispm

Delphi 利用hook api函数openprocess与terminateprocess来防止任务管理器结束进程

Delphi10.3构造一个json数据的第二种方法,并格式化输出

Delphi中获取打印机设备名和端口名

Delphi for 循环输出 a-z

Delphi使焦点固定到一个button上

Delphi 操作“任务栏”

Delphi 与 c# 生成不带bom的utf8文件

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...