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 ip地址转换

Delphi xe更改ttrayicon系统任务栏图标(无模糊)

Delphi 非主窗体(即子窗体)在任务栏显示按钮

vclzip 3.10.1的简单使用示例

Delphi监控指定进程防止被关闭

Delphi 判断上午还是下午

Delphi 动态给combobox赋值,从combobox中取值

Delphi 利用hook技术实现键盘监控

Delphi with 语句的妙用

Delphi 检测判断字符串是否包含有中文字符

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



打赏

取消

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

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

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

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

评论

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