zoukankan      html  css  js  c++  java
  • fastscript调用delphi方法和DELPHI调用FASTSCRIPT方法

    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. 

  • 相关阅读:
    phpMyAdmin cannot login to mysql server
    emulation 与 simulation 的区别
    C++类构造函数中的成员初始化
    KEY IDEA For Topology-based Analysis
    NOTES ON [Efficient and Cost-Effective Hybrid Congestion Control for HPC Interconnection Networks]
    Install Google Chrome On Ubuntu 14.04
    idea 远程debug调试
    癌细胞作用于身体
    应用高cpu高内存占用
    Jackson总结:常用注解、整合spring、自定义JsonSerializer
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/4518745.html
Copyright © 2011-2022 走看看