Is there a good scripting Pascal-like language for Delphi?

蓝咒 提交于 2019-12-03 11:53:12

问题


I'm looking for a good free scripting engine for Delphi. I want to add scripting to an application so that I can write small test scripts. Specifically I need:

  • Pascal-like syntax
  • current (I looked at RemObjects Pascal Scripting but it is "obsolete" according to a posting I saw).

I don't need full language support, just the basics. I saw this: https://stackoverflow.com/questions/226135/scripting-library-for-delphi but I'm assuming things have moved on a little since then.

All I want to be able to do is add a memo component to my program, and at run-time add a fragment of source to the memo and click on a go button. I want the script to be able to access my application's variables and functions.

What's the easiest path to accomplishing this? Example program follows.

program Project31;

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

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm36, Form36);
  Application.Run;
end.

.

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.

.

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

回答1:


Try the dwscript library which is currently maintained by Eric Grange.




回答2:


The Jedi JVCL also includes TJvInterpreter which is a very lightweight (small) interpreter, but with much more limited features than dwscript.

For very small (User entered formulas, or simple string and numeric processing tasks) JvInterpreter has worked quite well for me.




回答3:


Few years ago I used to work with Pax Compiler in combination with this Forms Editor.




回答4:


FastScript from FastReport (stack does not allow to give a link). Includes PascalScript, C++Script, JScript and BasicScript. PascalScript seems to be exactly what you ask for.




回答5:


Try embedding Lua. See Lua 5.1 for Delphi for instance.



来源:https://stackoverflow.com/questions/12344068/is-there-a-good-scripting-pascal-like-language-for-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!