• 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. 

  • 相关阅读:
    linux下tomcat内存溢出
    leetcode
    HDU 4810 Wall Painting (位操作-异或)
    详解Java中的访问控制修饰符(public, protected, default, private)
    mpvue开发微信小程序之时间+日期选择器
    多行文本溢出隐藏
    swift 多态函数方式
    swift 多态函数方式
    swift 多态函数方式
    swift 多态函数方式
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/4518745.html
Copyright © 2020-2023  润新知