如何通过Delphi在另一脚本中调用执行脚本?
- 内容介绍
- 文章标签
- 相关推荐
本文共计319个文字,预计阅读时间需要2分钟。
假设您想将以下伪代码转换为实际可运行的代码,并且要求不使用任何外部库,下面是一个可能的Python实现:
pythondef Add(a, b: int) -> int: result=a + b return result
def int_to_str(n: int) -> str: return str(n)
a=1b=2c=Add(a, b)print(int_to_str(c))
假设我将此函数保存在某个脚本中:function Add(a,b:integer):integer; begin result:=a+b; end;
我有另一个脚本如下:
var a,b,c:integer; a:=1; b:=2; c:=Add(a,b); println(inttoStr(c));
如何编译这两个脚本并使用Delphi中的dwscript从第二个脚本调用第一个脚本?
假设一个文件被称为“file1.extension”,它的内容是:function Add(a,b:integer):integer; begin result:=a+b; end;
和另一个名为“main.extension”的文件,内容如下:
var a,b,c:integer; a:=1; b:=2; c:=Add(a,b); println(inttoStr(c));
你需要在“main.extension”文件的开头添加以下行:
// note that file name is case sensitive // file1.extension <> FILE1.EXTENSION // include_once is to solve cycle-includes // i.e. file1.extension includes main.extension and vice-versa {$include_once 'file1.extension'} // or include if file1.extension does not require functions/objects/variables/etc. // from main.extension {$include 'file1.extension'}
我建议使用{$include_once …}而不是{$include …}.
本文共计319个文字,预计阅读时间需要2分钟。
假设您想将以下伪代码转换为实际可运行的代码,并且要求不使用任何外部库,下面是一个可能的Python实现:
pythondef Add(a, b: int) -> int: result=a + b return result
def int_to_str(n: int) -> str: return str(n)
a=1b=2c=Add(a, b)print(int_to_str(c))
假设我将此函数保存在某个脚本中:function Add(a,b:integer):integer; begin result:=a+b; end;
我有另一个脚本如下:
var a,b,c:integer; a:=1; b:=2; c:=Add(a,b); println(inttoStr(c));
如何编译这两个脚本并使用Delphi中的dwscript从第二个脚本调用第一个脚本?
假设一个文件被称为“file1.extension”,它的内容是:function Add(a,b:integer):integer; begin result:=a+b; end;
和另一个名为“main.extension”的文件,内容如下:
var a,b,c:integer; a:=1; b:=2; c:=Add(a,b); println(inttoStr(c));
你需要在“main.extension”文件的开头添加以下行:
// note that file name is case sensitive // file1.extension <> FILE1.EXTENSION // include_once is to solve cycle-includes // i.e. file1.extension includes main.extension and vice-versa {$include_once 'file1.extension'} // or include if file1.extension does not require functions/objects/variables/etc. // from main.extension {$include 'file1.extension'}
我建议使用{$include_once …}而不是{$include …}.

