天软金融分析.NET函数大全 > TSL函数 > 第三方交互函数 > 外部交互扩展调用接口 > DLL外部函数引入

申明函数时使用常量/常量计算结果指定动态库名称    

  •   在不同平台(Win、Linux)上,同一动态库文件名并不相同。
      此时,可使用常量/常量计算结果指定动态库名称,与条件编译相结合,根据不同的平台调用同一动态库中函数。
    范例


    范例一:使用常量指定动态库名称
    obj := new testClass();
    obj.test();
    type testClass=class()
      {$IFDEF LINUX}
      const krnl="libTSLkrnl.so";
      {$ELSE}
      const krnl="tslkrnl.dll";
      {$ENDIF}
      function test()
      begin
        t := TSstrtofloat("1.23");
        echo datatype(t),"\r\n";
        echo t,"\r\n";
      end
      Function TSstrtofloat(s:string):double;external krnl name "TS_strtofloat";
    end

    Linux结果:

    Windows结果:


    范例二:使用常量计算结果指定动态库名称
    obj := new testClass();
    obj.test();
    type testClass=class()
      const krnl="tslkrnl";
      const ext="dll";
      function test()
      begin
        t := TSstrtofloat("1.23");
        echo datatype(t),"\r\n";
        echo t,"\r\n";
      end
      Function TSstrtofloat(s:string):double;external krnl$"."$ext name "TS_strtofloat";
    end

    结果: