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增加三方控件的更多相关文章

  1. fastscript增加三方控件之二

    fastscript增加三方控件之二 unit fs_BsDataSet; interface {$i fs.inc} uses SysUtils, Classes, fs_iinterpreter, ...

  2. Delphi以及三方控件的源代码规模

    这些项目大多数使用C++或者C编写,使用SourceCounter-3.5.33.73工具来统计源代码数量,本来是这里下载的: https://code.google.com/p/boomworks/ ...

  3. 五种情况下会刷新控件状态(刷新所有子FWinControls的显示)——从DFM读取数据时、新增加子控件时、重新创建当前控件的句柄时、设置父控件时、显示状态被改变时

    五种情况下会刷新控件状态(刷新控件状态才能刷新所有子FWinControls的显示): 在TWinControls.PaintControls中,对所有FWinControls只是重绘了边框,而没有整 ...

  4. Delphi编程之好用的三方控件

    Delphi的强大与其庞大的组件库息息相关,目前的XE10.1版本已自带FastReport和GDI+等,下面我们来看一下几个非常强大且实用的组件库 一.DevExpress套件 Dev包含Grid. ...

  5. wpf动态增加删除控件

    我在xaml中定义了一个名字为morepictureWrapPan为WrapPanel,然后将控件添加在此WrapPanel中.由于要实现控件的删除功能,所以增加的textbox和button的名字都 ...

  6. duilib 增加gif控件(基于gdi+,可控制播放暂停,自动设置大小)

    转载请说明原出处,谢谢~~:http://blog.csdn.net/zhuhongshu/article/details/42502081 因为项目需要我需要给duilib增加一个gif控件,目前已 ...

  7. iOS 简单易用的二维码扫描及生成二维码三方控件LFQRCode,可灵活自定义UI

    一.扫码 扫描的控件是一个view,使用者只需贴在自己的控制器内即可.其他UI用户可在自己控制器随便添加.代码如下 - (void)viewDidLoad { [super viewDidLoad]; ...

  8. Android UI设计中一些不错的示例及第三方控件

    1.二级ListView自定义布局ExpandableListView http://pan.baidu.com/s/1mhlJh12 密码:nhc2 2.ListView实现各种动画效果ListVi ...

  9. 关于图片加载非常爽的一个三方控件 fresco,一个三fresco

    Hi  EveryBody 今天来玩一个非常爽的控件 fresco 到底有多爽呢 接着看就知道了 首先 来看看fresco 是个神马东西 https://github.com/facebook/fre ...

随机推荐

  1. POJ:3041-Asteroids(匈牙利算法模板)

    传送门:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Description Bes ...

  2. 奇数结点升序偶数结点降序的单链表排序(Python实现)

    题目 一个链表,奇数结点升序,偶数结点降序,要求变成一个全升序的链表. 例如:1->8->2->7->3->6->4->5,变为1->2->3-& ...

  3. 使用Blend的一些问题和技巧

    WPF开发,界面处理首选Blend,如果你开发了两年WPF都没接触过blend(当然这种几率不高),或者你刚接触WPF,可以考虑使用Blend,这货也算得上一个神器,上手也不难.以下有两位讲得不错,大 ...

  4. BZOJ 4896: [Thu Summer Camp2016]补退选

    trie树+vector+二分 别忘了abs(ans) #include<cstdio> #include<algorithm> #include<vector> ...

  5. NetCore 2.0 应用程序在centos 7上通过docker发布

    一  安装netcore 2.0 SDK 在centos 上面安装netcore 2.0 与window上面是不太一样的,注意,linux是不支持同时安装两个版本的.netcore SDK的,由于我之 ...

  6. JSON Undefined 问题

    在IE6和IE7浏览器下或在IE8-IE10浏览器文档模式为IE7及以下时,控制台会报错:JSON is undefined. 这种错误在IE6和IE7浏览器下出现很正常,因为JSON在IE8+浏览器 ...

  7. 第3章 jquery中的事件和动画

    一,jquery中的事件 (1).执行时机 $(document).ready()和window.onload方法有相似的功能,但是在执行时机方面有区别,windwo.onload在网页中所有的元素包 ...

  8. 递归函数的写法(以strcpy函数为例)

    1. 递归函数模板 递归的前提是,找到一个公共子问题(或公共操作),然后将该函数构造为递归函数. retType function( ... ) { 结束条件 { [处理] 返回 } 递归条件 { [ ...

  9. php preg_replace去除html xml 注释

    php preg_replace去除html xml 注释 //不确定是否最优 $content = preg_replace('/<!--((?!-->).)*-->/s', '' ...

  10. HDU4548 美素数

    Problem Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识. 问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素 ...