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

6

13

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
Driskell answered 10/9, 2012 at 0:17 Comment(5)
I'd still personally prefer PascalScript. The lack of missing support for the 64-bit Delphi compiler might be the weakness, but when you're using 32-bit Delphi compiler (support is currently up to Delphi XE2), then you'll be fine, I think. PascalScript has currently low priority at bug fixing (mostly for issues found for the 64-bit compiler), but it doesn't mean it isn't stable for 32-bit. Projects like InnoSetup uses it and it's still alive. After a very quick search I don't think there's a free alternative in the same proofed quality.Did
Thanks @TLama. I had installed it for D2006 and XE1, but it didn't install any D10 BPLs, the ReadMe.html was a dead link, the last entry changes.txt file was "NEW Support for Borland Developer Studio 2006", so I wasn't confident. I'll look again. I would be interested to see what would be involved in getting my sample app running if you have the time and installed software.Driskell
I wouldn't take that changelog.txt file too seriously. There were many commits since the last time logged in that file, so I'd say they just stopped to log into that file.Did
See also #5560189Revenant
With Pascal Script there's an extended IDE available, called maXbox. The Art of Coding: maXbox is a script tool engine, compiler and source lib all in one exe to design and code your scripts! Pure Code for Object Scripting. Princip is simplicity and reduce to the max. The App is “out of the box” (self containment) and needs no installation nor registration. maxbox4.wordpress.comBopp
J
14

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

Johnsen answered 10/9, 2012 at 0:45 Comment(4)
Thanks @RRUZ. Any comments as to how it compares to PascalScript?Driskell
1. the dwscript supports the Delphi syntax and also add very nice extensions to the language 2. is actively maintained 3.) good documentation and samples 4. have an extensive unit tests set.Johnsen
I found this: #4890310 which was quite helpful. I'll definitely give it a try.Driskell
aarrgghh! BDS2006 no longer supported. The particular app I was wanting to fit an interpreter to is A D006 app. I don't know how much effort there would be in regressing the current release (supports 2009 and up) back to 2006.Driskell
A
5

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.

Argile answered 10/9, 2012 at 3:17 Comment(6)
is it possible to call routines and access variables in your application?Driskell
You have to write a bit of code, but yes, you can. Much less code in more recent versions of delphi, since RTTI and method invocation can now be done much more intelligently. But some code is required per unit you wish to make callable. I actually like having a wrapper control WHAT is accessible. Makes it harder for my script to crash my app.Argile
Thanks @Warren. I tried a "Hello World" app and was impressed with how easy it was to get going - even including a Delphi-like editor. There is some documentation here here but precious little in the way of examples going in the other direction - i.e. accessing application variables from the script. Is there any real JVCL help? Most of the stuff at wiki.delphi-jedi.org/wiki/JEDI_Visual_Component_Library seems to be empty and the JvInterpreter a welcome exception.Driskell
Another think I'm wondering about is whether it is possible to have a script executing from the app and still have the app continue on as normal - i.e. have the script run in the background and not as a blocking call - or do I need to run the script in a thread the script to do that?Driskell
I really doubt that would be stable, or easy to do. Lots of concurrency/thread issues for you to handle, making your wrapper code VERY COMPLEX.Argile
In 2016 I'd recommend doing this kind of thing OUT OF PROCESS.Argile
M
1

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

Monoplane answered 10/9, 2012 at 6:41 Comment(0)
B
1

enter image description here


Release Notes maXbox 4.7.5.20 Jan 2021 mX47


Add 25 Units + 4 Tutorials

1277 unit uPSI_SystemsDiagram.pas  Dendron
1278 unit uPSI_qsFoundation.pas    Dendron
1279 uPSI_JclStringLists2          JCL  
1280 uPSI_cInternetUtils2          FLC
1281 uPSI_cWindows.pas             FLC
1282 uPSI_flcSysUtils.pas  +TBytes utils
1283 unit uPSI_RotImg.pas          DA 
1284 uPSI_SimpleImageLoader.pas    LAZ
1285 uPSI_HSLUtils.pas             LAZ
1286 uPSI_GraphicsMathLibrary.pas  EF
1287 unit uPSI_umodels.pas         DMath
1288 uPSI_flcStatistics.pas        FLC5
1289 uPSI_flcMaths.pas             FLC5
1290 uPSI_flcCharSet.pas
1291 uPSI_flcBits32.pas
1292 uPSI_flcTimers.pas
1293 uPSI_cBlaiseParserLexer.pas
1294 uPSI_flcRational.pas
1295 uPSI_flcComplex.pas
1296 unit uPSI_flcMatrix (uPSI_flcVectors.pas)
1297 unit uPSI_flcStringBuilder.pas
1298 unit PJResFile_Routines;
1299 uPSI_flcASCII.pas
1300 uPSI_flcStringPatternMatcher;
1301 unit uPSI_flcUnicodeChar.pas

Totals of Function Calls: 33282 SHA1: of 4.7.5.20 D82EAD01C58738887661428F94B207DB1D8FAEB5 CRC32: 768395C5 29.5 MB (31,012,768 bytes

Bopp answered 14/2, 2021 at 19:43 Comment(2)
This citation without linking to its source or any further comment is made because...?Vicentevicepresident
@Vicentevicepresident , Thanks you're right this was a missing point: maXbox is a script tool engine, compiler and source lib all in one exe to design and code your scripts like in a shellbook! Pure Code for Object Scripting. Principle is simplicity and reduce to the max. The App is “out of the box” (self containment) and needs no installation nor registration.Bopp
N
0

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.

Northward answered 10/9, 2012 at 16:30 Comment(1)
Question specifies Free. FastReport is commercial. Although it's good.Argile
R
0

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

Revenant answered 10/9, 2012 at 17:21 Comment(1)
Lua has an end keyword, and a function keyword but it's not very pascal-like.Argile

© 2022 - 2024 — McMap. All rights reserved.