开发者

PascalScript including other script per uses or include command

I have included the PascalScript engine into my software. My user now wants to write a whole set of scripts for this engine, and would like to know if it is possible to include other Scripts by an include or uses commmand.

What he wants to do is write one script that holds all kinds of constants/variables and another that does the logic. In the end he wants to include the constants into his logic scri开发者_开发问答pt.

I hope this was clear enough to understand.


I found out, heres how how do to it: The UsePreprocessor Property of the PascalScript compiler needs to be set to true. If so you can now use the following preprocessor command:

{$I filename.txt}

Also you need to implement the OnNeedFile Event of the compiler with something like the following example that I found on the net:

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;


(Please fix your question title)

I'm not entirely sure but afaik Pascalscript has no "file" concept. You could simply concat both parts before passing them to the interpreter, or have a small preprocessor look for the {$I } include statements and look the code to insert up.


If you set the conditional define to PS_USESSUPPORT and in the OnFindUnknownFile event you have to load the pas-file content into the output string.

Then you can use "Uses XYZ;".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜