fastscript增加三方控件
fastscript增加三方控件
A.关于如何使用第三方控件,增加方法、属性、事件)
举例如下:
如:有一控件为edtbutton:TedtButton,我们需要在动态脚本中使用该控件。我们采用如下方法:
我们可以把该控件申明在fs_iformsrtti单元里面(当然也可以申明在其他的单元如fs_idbrtti里面,但是遵守一个原则是尽量使得功能相似的控件放在同一个单元里面,这样只需要把该单元所对应的控件拖动到form上即可,提高系统运行效率)
如:fs_iformsrtti单元对应控件板上的fsiformsrtti。以此类推
AddClass(TedtButton, 'TControl');
对于增加方法:请看如下例子:
如需要增加Tedit类的CopyToClipboard、CutToClipboard、PasteFromClipboard方法。则代码如下所示:
with AddClass(TEdit, 'TWinControl') do
begin
AddMethod('procedure CopyToClipboard', CallMethod);
AddMethod('procedure CutToClipboard', CallMethod);
AddMethod('procedure PasteFromClipboard', CallMethod);
end;
在 CallMethod中需要增加相应方法的实现。
function TFunctions.CallMethod(Instance: TObject; ClassType: TClass;
const MethodName: String; var Params: Variant): Variant;
var
Form: TCustomForm;
begin
Result := 0;
if ClassType = TControl then
begin
if MethodName = 'HIDE' then
TControl(Instance).Hide
else if MethodName = 'SHOW' then
TControl(Instance).Show
else if MethodName = 'SETBOUNDS' then
TControl(Instance).SetBounds(Params[0], Params[1], Params[2], Params[3])
end
else if ClassType = TWinControl then
begin
if MethodName = 'SETFOCUS' then
TWinControl(Instance).SetFocus
end
else if ClassType = TEdit then //需要增加的实现(只是对于Tedit);
begin
if MethodName = uppercase('CopyToClipboard') then
Tedit(Instance).CopyToClipboard ;
if MethodName = uppercase('CutToClipboard') then
Tedit(Instance).CutToClipboard ;
if MethodName = uppercase('PasteFromClipboard') then
Tedit(Instance).PasteFromClipboard ;
end
End
对于增加属性:请看如下例子:
如需要增加TdataSet的RecordCount属性,则代码如下所示:
with AddClass(TDataSet, 'TComponent') do
begin
AddMethod('procedure Open', CallMethod);
……
AddProperty('FieldCount', 'Integer', GetProp, nil);
AddProperty('RecordCount', 'Integer',GetProp,nil); 因为RecordCount属性只有读没有写。
AddProperty('Active', 'Boolean', GetProp, SetProp);既能读又能写。
End
如果有写过程,则需要在 GetProp过程中增加相应属性的实现。
function TFunctions.GetProp(Instance: TObject; ClassType: TClass;
const PropName: String): Variant;
begin
…….
if ClassType = TField then
begin
……
Result := _TField.Size
else if PropName = 'VALUE' then
Result := _TField.Value
……
end
else if ClassType = TDataSet then
begin
……
else if PropName = 'FIELDCOUNT' then
Result := _TDataSet.FieldCount
else if PropName = 'RECORDCOUNT' then
Result := _TDataSet.RecordCount
……
end。
procedure TFunctions.SetProp(Instance: TObject; ClassType: TClass;
const PropName: String; Value: Variant);
……
if ClassType = TField then
begin
_TField := TField(Instance);
if PropName = 'ASBOOLEAN' then
_TField.AsBoolean := Value
else if PropName = 'ASCURRENCY' then
_TField.AsCurrency := Value
else if PropName = 'ASDATETIME' then
_TField.AsDateTime := Value
else if PropName = 'ASFLOAT' then
_TField.AsFloat := Value
else if PropName = 'ASINTEGER' then
_TField.AsInteger := Value
else if PropName = 'ASSTRING' then
_TField.AsString := Value
else if PropName = 'ASVARIANT' then
_TField.AsVariant := Value
else if PropName = 'VALUE' then
_TField.Value := Value
end
else if ClassType = TDataSet then
begin
_TDataSet := TDataSet(Instance);
if PropName = 'FILTER' then
_TDataSet.Filter := Value
else if PropName = 'FILTERED' then
_TDataSet.Filtered := Value
else if PropName = 'FILTEROPTIONS' then
_TDataSet.FilterOptions := IntToFilterOptions(Value)
else if PropName = 'ACTIVE' then
_TDataSet.Active := Value
end
……
B.调用Delphi过程:
1. 先创建事件处理方法:TfsCallMethodEvent
2. 然后再用调用TfsScript.AddMethod方法,第一个参数为Delphi方法的语法,第二个参数为TfsCallMethodEvent链接的一个句柄。
如在Delphi有一个过程为DelphiFunc,
…..
procedure TForm1.DelphiFunc(s: String; i: Integer);
begin
ShowMessage(s + ', ' + IntToStr(i));
end;
{TfsCallMethodEvent}
function TForm1.CallMethod(Instance: TObject; ClassType: TClass; const MethodName: String;
var Params: Variant): Variant;
begin
if MethodName = 'DELPHIFUNC' then //注意方法名称都为大写比较。
DelphiFunc(Params[0], Params[1]);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
{ clear all items }
fsScript1.Clear;
{ script text }
fsScript1.Lines := Memo1.Lines;
{ frGlobalUnit contains standard types and functions }
fsScript1.Parent := fsGlobalUnit;
{ make DelphiFunc procedure visible to a script }
fsScript1.AddMethod('procedure DelphiFunc(s: String; i: Integer)', CallMethod);
{ compile the script }
if fsScript1.Compile then
fsScript1.Execute else { execute if compilation was succesfull }
ShowMessage(fsScript1.ErrorMsg); { show an error message }
end;
C.调用FastScript过程:与调用Delphi函数类似。
举例说明:如果在动态脚本里面有一个'ScriptFunc'的一个过程,则在delphi代码里需要写如下:
fsScript1.Clear;
{ script text }
fsScript1.Lines := Memo1.Lines;
{ frGlobalUnit contains standard types and functions }
fsScript1.Parent := fsGlobalUnit;
{ make DelphiFunc procedure visible to a script }
{ compile the script }
if fsScript1.Compile then
{ Call script function with one string parameter and one integer param }
fsScript1.CallFunction('ScriptFunc', VarArrayOf(['Call ScriptFunc', 1])) else
ShowMessage(fsScript1.ErrorMsg); { show an error message }
end;
例如动态脚本内容如下:
procedure ScriptFunc(Msg: String; Num: Integer);
begin
ShowMessage('1st param: ' + Msg +
' 2nd param: ' + IntToStr(Num));
end;
begin
DelphiFunc('Call DelphiFunc', 1);
end.
fastscript增加三方控件的更多相关文章
- fastscript增加三方控件之二
fastscript增加三方控件之二 unit fs_BsDataSet; interface {$i fs.inc} uses SysUtils, Classes, fs_iinterpreter, ...
- Delphi以及三方控件的源代码规模
这些项目大多数使用C++或者C编写,使用SourceCounter-3.5.33.73工具来统计源代码数量,本来是这里下载的: https://code.google.com/p/boomworks/ ...
- 五种情况下会刷新控件状态(刷新所有子FWinControls的显示)——从DFM读取数据时、新增加子控件时、重新创建当前控件的句柄时、设置父控件时、显示状态被改变时
五种情况下会刷新控件状态(刷新控件状态才能刷新所有子FWinControls的显示): 在TWinControls.PaintControls中,对所有FWinControls只是重绘了边框,而没有整 ...
- Delphi编程之好用的三方控件
Delphi的强大与其庞大的组件库息息相关,目前的XE10.1版本已自带FastReport和GDI+等,下面我们来看一下几个非常强大且实用的组件库 一.DevExpress套件 Dev包含Grid. ...
- wpf动态增加删除控件
我在xaml中定义了一个名字为morepictureWrapPan为WrapPanel,然后将控件添加在此WrapPanel中.由于要实现控件的删除功能,所以增加的textbox和button的名字都 ...
- duilib 增加gif控件(基于gdi+,可控制播放暂停,自动设置大小)
转载请说明原出处,谢谢~~:http://blog.csdn.net/zhuhongshu/article/details/42502081 因为项目需要我需要给duilib增加一个gif控件,目前已 ...
- iOS 简单易用的二维码扫描及生成二维码三方控件LFQRCode,可灵活自定义UI
一.扫码 扫描的控件是一个view,使用者只需贴在自己的控制器内即可.其他UI用户可在自己控制器随便添加.代码如下 - (void)viewDidLoad { [super viewDidLoad]; ...
- Android UI设计中一些不错的示例及第三方控件
1.二级ListView自定义布局ExpandableListView http://pan.baidu.com/s/1mhlJh12 密码:nhc2 2.ListView实现各种动画效果ListVi ...
- 关于图片加载非常爽的一个三方控件 fresco,一个三fresco
Hi EveryBody 今天来玩一个非常爽的控件 fresco 到底有多爽呢 接着看就知道了 首先 来看看fresco 是个神马东西 https://github.com/facebook/fre ...
随机推荐
- zoj 4054
#define ll long long ; int t; ll ans,tmp; char s[N]; int main() { scanf("%d",&t); whil ...
- ACM-ICPC 2017 Asia Urumqi G. The Mountain
All as we know, a mountain is a large landform that stretches above the surrounding land in a limite ...
- Leetcode 81. 搜索旋转排序数组 II
题目链接 https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/description/ 题目描述 假设按照升序排序的数 ...
- 设置ubuntu12.04的dasher-自动隐藏,左上角
点击右上角的齿轮,--> “system setting”--“Appearance” 在“Look”标签中: Theme:Ambiance Launch icon size :32 选择桌面背 ...
- java启动的一些参数
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9001 -Dcom.sun.management.jmxremo ...
- python踩坑系列——报错后修改了.py文件,但是依然报错
一开始.py文件中的函数名大小写错了,但是在终端是对的,报错: 'module' object has no attribute '某函数名' 后来就去修改.py文件.结果重新import该.py文件 ...
- [PDOException] SQLSTATE[HY000] [2002] No such file or directory
编译安装PHP7之后,在安装mysql之后,用pdo操作数据库的时候,出现了此错误[PDOException] SQLSTATE[HY000] [2002] No such file or direc ...
- Spring c3p0连接池配置
数据库连接池 数据库连接池的基本思想就是为数据库连接建立一个“缓冲池”.预先在缓冲池中放入一定数量的连接,当需要建立数据库连接时,只需从“缓冲池”中取出一个,使用完毕之后再放回去.我们可以通过设定连接 ...
- hihoCoder #1157 建造金字塔
这道题我想了一天才想清楚做法.AC 了之后去看别人写的题解,都是三言两语意识流式描述,我并不能读懂.我觉得很自卑,为何人家解这道题如此轻松.不过,我还是决定把我的解法写下来,并且一定要写清楚. 思路 ...
- 浅谈android反调试之 API判断
反调试:利用Java层API来判断Android程序是否是处于被调试下. 1.直接调用系统的android.os.Debug.isDebuggerConnected()方法 我们进行动态调试的时候,其 ...