测试RemObjects Pascal Script
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, uPSComponent, StdCtrls, uPSCompiler, uPSUtils, uPSRuntime;
type
TTestFunction = function (Param1: Double; Data: string): LongInt of object;
TForm1 = class(TForm)
st: TPSScript;
Button1: TButton;
Button2: TButton;
procedure stCompile(Sender: TPSScript);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure stVerifyProc(Sender: TPSScript; Proc: TPSInternalProcedure;
const Decl: string; var Error: Boolean);
private
procedure ShowNewMessage(const AMessage: string);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
with st.Script do
begin
Add('Program test;');
Add('function TestFunction(Param1: Double; Data: String): Longint;');
Add('begin');
Add(' ShowNewMessage(''Param1:''+ FloatToStr(Param1)+ #13#10+ ''Data''+ Data);');
Add(' Result := 1234567;');
Add('end;');
Add('var MyVar: Integer;');
Add('begin');
Add(' MyVar := 1000;');
Add(' ShowNewMessage(''全局变量MyVar=''+IntToStr(MyVar)+'' '');//调用了Delphi中的方法');
Add('end.');
end;
if not st.Compile then
raise Exception.Create('编译的时候发生错误!');
st.Execute;
end;
//Delphi调用脚本中的方法
procedure TForm1.Button2Click(Sender: TObject);
var
meth: TTestFunction;
begin
meth := TTestFunction(st.GetProcMethod('TESTFUNCTION'));
if @meth= nil then
raise Exception.Create('Unable call TestFunction');
ShowMessage('Result:'+ IntToStr(meth(Pi, DateTimeToStr(Now))));
end;
//Delphi声明的方法 可以在脚本中调用
procedure TForm1.ShowNewMessage(const AMessage: string);
begin
ShowMessage('ShowNewMessage invoked:'+ #13#10+ AMessage);
end;
//在TPSScript控件的Compile事件中导出方法 这样就可以在脚本中调用了
procedure TForm1.stCompile(Sender: TPSScript);
begin
Sender.AddMethod(Self, @TForm1.ShowNewMessage,
'procedure ShowNewMessage (const AMessage: string);');
end;
//在调用脚本中的方法前触发TPSScript控件的VerifyProc事件验证函数类型[返回值,参数等信息]
procedure TForm1.stVerifyProc(Sender: TPSScript; Proc: TPSInternalProcedure;
const Decl: string; var Error: Boolean);
begin
if Proc.Name = 'TESTFUNCTION' then
begin
if not ExportCheck(Sender.Comp, Proc, [btS32, btDouble, btString], [pmIn, pmIn]) then
begin
Sender.Comp.MakeError('',ecCustomError, 'Function header for TestFunction does not match.');
Error := True;
end
else
begin
Error := False;
end;
end
else
Error := False;
end;
end.//还有一些功能没有测试 如设置脚本变量的值 获取脚本变量的值等
测试RemObjects Pascal Script的更多相关文章
- 使用RemObjects Pascal Script (转)
http://www.cnblogs.com/MaxWoods/p/3304954.html 摘自RemObjects Wiki 本文提供RemObjects Pascal Script的整体概要并演 ...
- 使用RemObjects Pascal Script
摘自RemObjects Wiki 本文提供RemObjects Pascal Script的整体概要并演示如何创建一些简单的脚本. Pascal Script包括两个不同部分: 编译器 (uPSCo ...
- 在delphi中嵌入脚本语言--(译)RemObjects Pascal Script使用说明(1)(译)
翻譯這篇文章源於我的一個通用工資計算平台的想法,在工資的計算中,不可避免的需要使用到自定義公式,然而對於自定義公式的實現,我自己想了一些,也在網上搜索了很多,解決辦法大致有以下幾種: 1. 自己寫代碼 ...
- Inno Setup Pascal Script to search for running process
I am currently trying to do a validation at the uninstall moment. In a Pascal script function, in In ...
- Pascal Script
MsgBox http://www.jrsoftware.org/ishelp/index.php?topic=isxfunc_msgbox ExpandConstant http://www.jrs ...
- delphi一些小技巧 从别处看到
开发环境-------- Delphi 7是一个很经典的版本,在Win2000/XP下推荐安装Delphi 7来开发软件,在Vista下推荐使用Delphi 2007开发软件.安装好Delphi ...
- (转载)Delphi开发经验谈
Delphi开发经验谈 开发环境-------- Delphi 7是一个很经典的版本,在Win2000/XP下推荐安装Delphi 7来开发软件,在Vista下推荐使用Delphi 2007开发软件. ...
- Pascal编译器大全(非常难得)
http://www.pascaland.org/pascall.htm Some titles (french) : Compilateurs Pascal avec sources = compi ...
- 测试框架Mocha与断言expect
测试框架Mocha与断言expect在浏览器和Node环境都可以使用除了Mocha以外,类似的测试框架还有Jasmine.Karma.Tape等,也很值得学习. 整个项目源代码: 为什么学习测试代码? ...
随机推荐
- 【驱动】input子系统整体流程全面分析(触摸屏驱动为例)【转】
转自:http://www.cnblogs.com/lcw/p/3294356.html input输入子系统整体流程 input子系统在内核中的实现,包括输入子系统(Input Core),事件处理 ...
- linux,mac安装sentry
linux,mac安装sentry 最近需要一个日志监视系统所以选择了sentry.以下是用mac安装,看需求量linux安装类似后面的文章会补充. 安装docker https://download ...
- 010_MAC下权限问题的那些事
一. arun:bin arunyang$ sh catalina.sh start #启动tomcat报一堆的没有权限~~~~(>_<)~~~~ 二.解决如下 aru ...
- tomcat启动报错:Injection of autowired dependencies failed
tomcat启动报错:Injectjion of autowired dependencies failed 环境: 操作系统:centos6.5 tomcat: 7.0.52 jdk:openjdk ...
- php里获取第一个中文首字母并排序
需求里结算首页需要按门店的首字母A-Z排序.我的数据结构原本是这样的: Array ( [0] => Array ( [sid] => 2885842 [recetcstoredpay] ...
- SURF 特征匹配
参考:http://www.cnblogs.com/ronny/p/4045979.html,博主对源码进行了分析,不过很多没看明白. 分为几个部分.积分图:借助积分图像,图像与高斯二阶微分模板的滤波 ...
- 《jquery实战》javascript 必知必会(1)
A1 javascript对象的基本原理 JS 的 Object 与其他兄弟面向对象所定义的根本对象,几乎没有什么共同之处. JS 的 Object 一旦创建,它不持有任何数据,而且不表示什么语义. ...
- .NetCore 实现分页控件(URL分页)实战
上一篇文章介绍了分页控件的具体实现方式,接下来我们就来做一个分页控件 后台数据处理就过度的介绍,下面针对URL分页中的下面几点做说明: 1.搜索条件的状态保持 2.点击分页需要带上搜索条件 3.页码的 ...
- #JS 窗口resize避免触发多次
window窗口改变时触发resize,如何避免多次执行,设置一个300ms定时器即可. //窗口变化监听,避免resize多次执行卡顿 var resizeTimer = null; $(windo ...
- 西安电子科技大学第16届程序设计竞赛网络同步赛 G-小国的复仇
sb找规律. 分解因数. #include<bits/stdc++.h> #define LL long long #define fi first #define se second # ...