Delphi是否有很好的脚本化Pascal样语言? [英] Is there a good scripting Pascal-like language for Delphi?

查看:323
本文介绍了Delphi是否有很好的脚本化Pascal样语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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




  • 类似帕斯卡的语法

  • current(我看过RemObjects Pascal Scripting但是根据我看到的一个帖子,它是过时的。



我不需要完整的语言支持,只是基础知识。我看到了这一点: Delphi脚本库,但我假设事情已经有一点移动了所有我想要做的就是在我的程序中添加一个备忘录组件,并在运行时添加一个源代码片段到备忘录,然后单击一个去按钮。我希望脚本能够访问我的应用程序的变量和函数。



完成这一过程最简单的途径是什么?示例程序如下。

 程序Project31; 

使用
表单,
Unit36在'Unit36.pas'{Form36};

{$ R * .res}

begin
Application.Initialize;
Application.CreateForm(TForm36,Form36);
Application.Run;
结束。

单位36; 

接口

使用
Windows,消息,SysUtils,变体,类,图形,控件,窗体,
对话框,StdCtrls;

type
TForm36 = class(TForm)
Button1:TButton;
Memo1:TMemo;
procedure Button1Click(Sender:TObject);
private
{私人声明}
public
{公开声明}
end;

var
Form36:TForm36;

实现

{$ R * .dfm}

procedure RoutineInMyApplication;

begin
ShowMessage('Hello from my Application');
结束

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

结束。

 对象Form36:TForm36 
Left = 0
顶部= 0
Caption ='Form36'
ClientHeight = 174
ClientWidth = 391
颜色= clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name ='Tahoma'
Font.Style = [ ]
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
对象Button1:TButton
左= 300
顶部= 72
宽度= 75
高度= 25
Caption ='Button1'
TabOrder = 0
OnClick = Button1Click
end
对象Memo1:TMemo
左= 8
顶部= 21
宽度= 241
高度= 145
Lines.Strings =(
'开始'
'ShowMessage('#39'世界'#39');'
'CallSomehow(RoutineInMyApplication);'
'end。'
'')
TabOrder = 1
end
end


解决方案

尝试 dwscript 库,由 Eric Grange


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: 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

解决方案

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

这篇关于Delphi是否有很好的脚本化Pascal样语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆