Delphi是否有一个很好的脚本Pascal式语言?

ros*_*mcm 13 delphi scripting pascal scripting-language remobjects

我正在为Delphi寻找一个好的免费脚本引擎.我想为应用程序添加脚本,以便我可以编写小的测试脚本.具体来说我需要:

  • 类Pascal语法
  • 当前(我看了RemObjects Pascal Scripting,但根据我看到的帖子,它已经"过时了").

我不需要全面的语言支持,只需要基础知识.我看到了这个:https://stackoverflow.com/questions/226135/scripting-library-for-delphi但是我假设事情已经发生了一些变化.

我想要做的就是在我的程序中添加一个备忘录组件,并在运行时向备忘录添加一个源代码片段,然后单击一个go按钮.我希望脚本能够访问我的应用程序的变量和函数.

实现这一目标的最简单方法是什么?示例程序如下.

program Project31;

uses
  Forms,
  Unit36 in 'Unit36.pas' {Form36};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm36, Form36);
  Application.Run;
end.
Run Code Online (Sandbox Code Playgroud)

.

unit Unit36;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm36 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form36: TForm36;

implementation

{$R *.dfm}

procedure RoutineInMyApplication ;

begin
ShowMessage ('Hello from my Application') ;
end ;

procedure TForm36.Button1Click(Sender: TObject);
begin
//ExecuteScript (Memo1.Lines) ;
end ;

end.
Run Code Online (Sandbox Code Playgroud)

.

object Form36: TForm36
  Left = 0
  Top = 0
  Caption = 'Form36'
  ClientHeight = 174
  ClientWidth = 391
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 300
    Top = 72
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Memo1: TMemo
    Left = 8
    Top = 21
    Width = 241
    Height = 145
    Lines.Strings = (
      'begin'
      'ShowMessage  ('#39'Hello world'#39') ;'
      'CallSomehow (RoutineInMyApplication) ;'
      'end.'
      ' ')
    TabOrder = 1
  end
end
Run Code Online (Sandbox Code Playgroud)

RRU*_*RUZ 14

试试dwscript目前由Eric Grange维护的图书馆.


War*_* P 5

Jedi JVCL 还包括 TJvInterpreter,它是一个非常轻量级(小型)的解释器,但与 dwscript 相比,其功能有限。

对于非常小的(用户输入的公式,或简单的字符串和数字处理任务)JvInterpreter 对我来说效果很好。