• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

fastscript调用delphi方法和DELPHI调用FASTSCRIPT方法

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

fastscript调用Delphi过程:  
1. 先创建事件处理方法:TfsCallMethodEvent 
2. 然后再用调用TfsScript.AddMethod方法,第一个参数为Delphi方法的语法,第二个参数为TfsCallMethodEvent链接的一个句柄。 如在Delphi有一个过程为DelphiFunc, ….. 
procedure TForm1.DelphiFunc(s: String; i: Integer);  begin  
  ShowMessage(s + ', ' + IntToStr(i));  end;   
{TfsCallMethodEvent} 
function TForm1.CallMethod(Instance: TObject; ClassType: TClass; const MethodName: String;  
  var Params: Variant): Variant;  begin  
 if MethodName = 'DELPHIFUNC' then  //注意方法名称都为大写比较。   DelphiFunc(Params[0], Params[1]);  end;  
procedure TForm1.Button1Click(Sender: TObject); begin 
  { clear all items }   

fsScript1.Clear;   

{ script text } 

  fsScript1.Lines := Memo1.Lines; 
  { frGlobalUnit contains standard types and functions }  

 fsScript1.Parent := fsGlobalUnit; 
  { make DelphiFunc procedure visible to a script }   

fsScript1.AddMethod('procedure DelphiFunc(s: String; i: Integer)', CallMethod);  
  { compile the script }   

if fsScript1.Compile then     

fsScript1.Execute else  

 { execute if compilation was succesfull }    

 ShowMessage(fsScript1.ErrorMsg);

 { show an error message } 

end; 

 

 

DELPHI调用FASTSCRIPT脚本

例如:如果在动态脚本里面有一个'ScriptFunc'的一个过程,则在delphi代码里需要写如下: 
  fsScript1.Clear;   { script text } 
  fsScript1.Lines := Memo1.Lines; 
  { frGlobalUnit contains standard types and functions }   fsScript1.Parent := fsGlobalUnit; 
  { make DelphiFunc procedure visible to a script }  
  { compile the script }   if fsScript1.Compile then 
    { Call script function with one string parameter and one integer param }     fsScript1.CallFunction('ScriptFunc', VarArrayOf(['Call ScriptFunc', 1])) else     ShowMessage(fsScript1.ErrorMsg); { show an error message } end;  
例如动态脚本内容如下: 
procedure ScriptFunc(Msg: String; Num: Integer); begin 
  ShowMessage('1st param: ' + Msg +      '  2nd param: ' + IntToStr(Num)); end;  
begin 
  DelphiFunc('Call DelphiFunc', 1);  end. 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
delphi通过TADOConnection组件直接连接MSSQL数据库并读写数据。发布时间:2022-07-18
下一篇:
delphi常用的将窗口置前的函数发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap