我已将PascalScript引擎包含到我的软件中。我的用户现在想为此引擎编写一整套脚本,并想知道是否可以通过includeuses指令包括其他脚本。

他想要做的是编写一个脚本,其中包含所有常量/变量,而另一个脚本则具有逻辑。最后,他希望将常量包括在他的逻辑脚本中。

我希望这一点足够清楚可以理解。

最佳答案

我发现了,这是怎么做的:
PascalScript编译器的UsePreprocessor属性需要设置为true。如果是这样,您现在可以使用以下预处理程序命令:

{$ I filename.txt}

另外,您还需要使用下面在网上找到的示例来实现编译器的OnNeedFile Event:

function TForm1.ceNeedFile(Sender: TObject; const OrginFileName: String;
var FileName, Output: String): Boolean;
var
  path: string;
  f: TFileStream;
begin
  Path := ExtractFilePath(ParamStr(0)) + FileName;
  try
    F := TFileStream.Create(Path, fmOpenRead or fmShareDenyWrite);
  except
    Result := false;
    exit;
  end;
  try
    SetLength(Output, f.Size);
    f.Read(Output[1], Length(Output));
  finally
    f.Free;
  end;
  Result := True;
end;

10-07 19:09
查看更多