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.  


相关阅读 >>

Delphixe4 版本中,已针对移动平台 引入了 arc 模型

dekphi 智能《疯狂刷新》辅助工具v3.1更新开源

Delphi 双击隐藏tabsheet

Delphi 判断尾串是否匹配,不分大小写

Delphi sql语句查询最新的各个台位的最后一个检测值

Delphi里如何限制form的大小

Delphi检测用户是否具有administrator权限

建议大家使用fastmm

Delphi idpop3收邮件

Delphi正则表达式匹配中文

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



打赏

取消

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

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

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

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

评论

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