测试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等,也很值得学习. 整个项目源代码: 为什么学习测试代码? ...
随机推荐
- linux串口驱动分析【转】
转自:http://blog.csdn.net/hanmengaidudu/article/details/11946591 硬件资源及描述 s3c2440A 通用异步接收器和发送器(UART)提供了 ...
- 关于内核中spinlock的一些个人理解 【转】
由于2.6内核可以抢占,应该在驱动程序中使用 preempt_disable() 和 preempt_enable(),从而保护代码段不被抢占(禁止 IRQ 同时也就隐式地禁止了抢占).preempt ...
- nginx开启gzip压缩前端css,js
利用nginx实现前后端分离, nginx配置文件,nginx.conf配置采用gzip压缩: 在server中添加: gzip on; #开启gzip gzip_min_length 1k; #低于 ...
- spfa学习笔记
序 spfa它死了 --by 大佬 但是本蒟蒻还是一如既往的使用spfa... 因为太弱了,其他什么都不会.于是就疯狂开O2跪倒在spfa上. 例题--汽车加油行驶问题 loj跳转链接 luogu跳转 ...
- 浙江省“一卡通”异地就医,C#调用省一卡通动态库
前言,最近学习调用 浙江省一卡通业务,主要就是调用一个DLL,动态库文件,这个动态库是浙大网新研发的. 借着自学的机会把心得体会都记录下来,方便感兴趣的小伙伴学习与讨论. 内容均系原创,欢迎大家转载分 ...
- Android Studio从2.3升级到3.1注意事项
原文:https://blog.csdn.net/lithiumyoung/article/details/80111111 Android Studio从2.3升级到3.1注意事项 项目根目录下的b ...
- NOIP2018濒死记
已经复课常规三个多星期了...终于有时间来写Noip2018游记了.当时的一些想法可能都不记得了...我的OI生涯也时日无多了.也许一开始我的选择就是错的,我之前就这么想,只不过现在更加确信了而已.等 ...
- 关于 Google 与 Chrome
不断更新... 查看chrome版本 chrome浏览器中输入 chrome://version/ Chrome吧 :http://tieba.baidu.com/f?kw=chrome&i ...
- 命令:install
简介 从命令的名字上来看,会让人误以为这是一个和安装相关的命令. 其实不然,install命令用于复制文件(cp)或创建空目录(mkdir)并设置相关的属性(chown.chmod). 这里的属性包含 ...
- Java NIO-3
http://itindex.net/detail/55603-java-nio-%E6%8A%80%E6%9C%AF