Search code examples
delphiscriptingpascalscripting-languageremobjects

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


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

Solution

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