fastscript增加三方控件之二

unit fs_BsDataSet;

interface

{$i fs.inc}

uses
SysUtils, Classes, fs_iinterpreter, fs_itools, fs_ievents,
DB,Bs_DataSet,fs_iclassesrtti,System.Variants;

type
TBsDBRTTI = class(TBsDataSet); // fake component

TBsDatasetNotifyEvent = class(TfsCustomEvent)
public
procedure DoEvent(Dataset: TBsDataSet);
function GetMethod: Pointer; override;
end;

TBsDataSetErrorEvent = class(TfsCustomEvent)
public
procedure DoEvent(DataSet: TDataSet; E: EDatabaseError;var Action: TDataAction);
function GetMethod: Pointer; override;
end;

TBsFilterRecordEvent = class(TfsCustomEvent)
public
procedure DoEvent(DataSet: TBsDataSet; var Accept: Boolean);
function GetMethod: Pointer; override;
end;

TBsFieldGetTextEvent = class(TfsCustomEvent)
public
procedure DoEvent(Sender: TField; var Text: String; DisplayText: Boolean);
function GetMethod: Pointer; override;
end;

type
TBsFunctions = class(TfsRTTIModule)
private
function CallMethod(Instance: TObject; ClassType: TClass;
const MethodName: String; Caller: TfsMethodHelper): Variant;
function GetProp(Instance: TObject; ClassType: TClass;
const PropName: String): Variant;
procedure SetProp(Instance: TObject; ClassType: TClass;
const PropName: String; Value: Variant);
public
constructor Create(AScript: TfsScript); override;
end;
VAR BsFunctions:TBsFunctions;
implementation

type
TByteSet = set of 0..7;
PByteSet = ^TByteSet;

{ TfsDatasetNotifyEvent }

procedure TBsDatasetNotifyEvent.DoEvent(Dataset: TBsDataSet);
begin
CallHandler([Dataset]);
end;

function TBsDatasetNotifyEvent.GetMethod: Pointer;
begin
Result := @TBsDatasetNotifyEvent.DoEvent;
end;

procedure TBsDataSetErrorEvent.DoEvent(DataSet: TDataSet; E: EDatabaseError;var Action: TDataAction);
begin
CallHandler([Dataset,@E,@Action]);
Action := Handler.Params[2].Value;
end;

function TBsDataSetErrorEvent.GetMethod: Pointer;
begin
Result := @TBsDataSetErrorEvent.DoEvent;
end;

{ TfsFilterRecordEvent }

procedure TBsFilterRecordEvent.DoEvent(DataSet: TBsDataSet; var Accept: Boolean);
begin
CallHandler([DataSet, Accept]);
Accept := Handler.Params[1].Value;
end;

function TBsFilterRecordEvent.GetMethod: Pointer;
begin
Result := @TBsFilterRecordEvent.DoEvent;
end;

{ TfsFieldGetTextEvent }

procedure TBsFieldGetTextEvent.DoEvent(Sender: TField; var Text: String; DisplayText: Boolean);
begin
CallHandler([Sender, Text, DisplayText]);
Text := Handler.Params[1].Value;
end;

function TBsFieldGetTextEvent.GetMethod: Pointer;
begin
Result := @TBsFieldGetTextEvent.DoEvent;
end;

{ TFunctions }

constructor TBsFunctions.Create(AScript: TfsScript);
begin
inherited Create(AScript);
with AScript do
begin
AddEnum('TDataAction','daFail, daAbort, daRetry');
AddEnumSet('TIndexOptions', 'ixPrimary, ixUnique, ixDescending, ixCaseInsensitive,ixExpression, ixNonMaintained');
with AddClass(Exception,'TObject') do
begin

end;
with AddClass(EDatabaseError,'Exception') do
begin

end;
with AddClass(TIndexDefs,'TCollection') do
begin
AddMethod('procedure Add(const Name,Fields:string;Options: TIndexOptions)',CallMethod);
end;
with AddClass(TBsDataSet, 'TDataSet') do
begin
AddMethod('procedure OpenData', CallMethod);
AddMethod('procedure OpenList', CallMethod);
AddMethod('procedure OpenPackList', CallMethod);
AddMethod('procedure OpenListUP', CallMethod);
AddMethod('procedure OpenListDown', CallMethod);
AddMethod('procedure SaveData', CallMethod);

AddMethod('procedure Open', CallMethod);
AddMethod('procedure Close', CallMethod);
AddMethod('procedure First', CallMethod);
AddMethod('procedure Last', CallMethod);
AddMethod('procedure Next', CallMethod);
AddMethod('procedure Prior', CallMethod);
AddMethod('procedure Cancel', CallMethod);
AddMethod('procedure Delete', CallMethod);
AddMethod('procedure Post', CallMethod);
AddMethod('procedure Append', CallMethod);
AddMethod('procedure Insert', CallMethod);
AddMethod('procedure Edit', CallMethod);
AddConstructor('constructor Create(AOwner: TComponent)',CallMethod);

AddMethod('function FieldByName(const FieldName: string): TField', CallMethod);
AddMethod('procedure GetFieldNames(List: TStrings)', CallMethod);
AddMethod('function FindFirst: Boolean', CallMethod);
AddMethod('function FindLast: Boolean', CallMethod);
AddMethod('function FindNext: Boolean', CallMethod);
AddMethod('function FindPrior: Boolean', CallMethod);
AddMethod('procedure FreeBookmark(Bookmark: TBookmark)', CallMethod);
AddMethod('function GetBookmark: TBookmark', CallMethod);
AddMethod('procedure GotoBookmark(Bookmark: TBookmark)', CallMethod);
AddMethod('function Locate(const KeyFields: string; const KeyValues: Variant;' +
'Options: TLocateOptions): Boolean', CallMethod);
AddMethod('function IsEmpty: Boolean', CallMethod);
AddMethod('procedure EnableControls', CallMethod);
AddMethod('procedure DisableControls', CallMethod);
AddMethod('procedure AddIndex(const Name, Fields: string;Options: TIndexOptions)',CallMethod);

AddProperty('Bof', 'Boolean', GetProp, nil);
AddProperty('Eof', 'Boolean', GetProp, nil);
AddProperty('FieldCount', 'Integer', GetProp, nil);
AddProperty('FieldDefs', 'TFieldDefs', GetProp, nil);
AddProperty('Fields', 'TFields', GetProp, nil);
AddProperty('Filter', 'string', GetProp, SetProp);
AddProperty('Filtered', 'Boolean', GetProp, SetProp);
AddProperty('FilterOptions', 'TFilterOptions', GetProp, SetProp);
AddProperty('Active', 'Boolean', GetProp, SetProp);
AddProperty('Data','OleVariant',GetProp,SetProp);
AddProperty('Params','TParams',GetProp,NIL);
AddProperty('IndexDefs','TIndexDefs',GetProp,nil);
AddProperty('FilterCode','string',GetProp,SetProp);
AddProperty('FilterLineListText','string',GetProp,SetProp);
AddProperty('FilterLineSQL','string',GetProp,SetProp);
AddProperty('FbMustFilter','Boolean',GetProp,SetProp);
AddProperty('FbPost','Boolean',GetProp,SetProp);
AddProperty('FbMultTable','Boolean',GetProp,SetProp);
AddProperty('RecordCount','Integer',GetProp,nil);
AddProperty('QFDataSetOpenSQL','string',GetProp,SetProp);

AddEvent('BeforeOpen', TBsDatasetNotifyEvent);
AddEvent('AfterOpen', TBsDatasetNotifyEvent);
AddEvent('BeforeClose', TBsDatasetNotifyEvent);
AddEvent('AfterClose', TBsDatasetNotifyEvent);
AddEvent('BeforeInsert', TBsDatasetNotifyEvent);
AddEvent('AfterInsert', TBsDatasetNotifyEvent);
AddEvent('BeforeEdit', TBsDatasetNotifyEvent);
AddEvent('AfterEdit', TBsDatasetNotifyEvent);
AddEvent('BeforePost', TBsDatasetNotifyEvent);
AddEvent('AfterPost', TBsDatasetNotifyEvent);
AddEvent('BeforeCancel', TBsDatasetNotifyEvent);
AddEvent('AfterCancel', TBsDatasetNotifyEvent);
AddEvent('BeforeDelete', TBsDatasetNotifyEvent);
AddEvent('AfterDelete', TBsDatasetNotifyEvent);
AddEvent('BeforeScroll', TBsDatasetNotifyEvent);
AddEvent('AfterScroll', TBsDatasetNotifyEvent);
AddEvent('OnCalcFields', TBsDatasetNotifyEvent);
AddEvent('OnFilterRecord', TBsFilterRecordEvent);
AddEvent('OnNewRecord', TBsDatasetNotifyEvent);
AddEvent('OnPostError', TBsDataSetErrorEvent);
end;
end;
end;

function TBsFunctions.CallMethod(Instance: TObject; ClassType: TClass;
const MethodName: String; Caller: TfsMethodHelper): Variant;
var
_TDataSet: TBsDataSet;
_TIndexDefs:TIndexDefs;

function IntToLocateOptions(i: Integer): TLocateOptions;
begin
Result := [];
if (i and 1) <> 0 then
Result := Result + [loCaseInsensitive];
if (i and 2) <> 0 then
Result := Result + [loPartialKey];
end;

function IntToIndexOptions(i: Integer): TIndexOptions;
begin
Result := [];
if (i = 1) then
Result := Result + [ixPrimary];
if (i = 2) then
Result := Result + [ixUnique];
if (i = 3) then
Result := Result + [ixDescending];
if (i = 4) then
Result := Result + [ixCaseInsensitive];
if (i = 5) then
Result := Result + [ixExpression];
if (i = 6) then
Result := Result + [ixNonMaintained];
end;
procedure IndexDefsAdd(QName, QFields: string;QArgs:Variant);
var ar:TIndexOptions;
i,n:Integer;
begin
n := VarArrayHighBound(QArgs, 1) + 1;
for i := 0 to n - 1 do
begin
ar :=ar+ IntToIndexOptions(QArgs[i]);
end;
_TIndexDefs.Add(QName,QFields,ar);
end;

procedure BsAddIndex(QName, QFields: string;QArgs:Variant);
var ar:TIndexOptions;
i,n:Integer;
begin
n := VarArrayHighBound(QArgs, 1) + 1;
for i := 0 to n - 1 do
begin
ar :=ar+ IntToIndexOptions(QArgs[i]);
end;
_TDataSet.AddIndex(QName,QFields,ar);
end;

begin
Result := 0;
if ClassType = TBsDataSet then
begin
_TDataSet := TBsDataSet(Instance);
if MethodName='OPENDATA' then
_TDataSet.OpenData
ELSE
if MethodName='OPENLIST' then
_TDataSet.OpenList
ELSE
if MethodName='OPENPACKLIST' then
_TDataSet.OpenPackList
ELSE
if MethodName='OPENLISTUP' then
_TDataSet.OpenListUP
ELSE
if MethodName='OPENLISTDOWN' then
_TDataSet.OpenListDown
ELSE
if MethodName='SAVEDATA' then
_TDataSet.SaveData
ELSE
if MethodName = 'OPEN' then
_TDataSet.Open
else if MethodName = 'CLOSE' then
_TDataSet.Close
else if MethodName = 'FIRST' then
_TDataSet.First
else if MethodName = 'LAST' then
_TDataSet.Last
else if MethodName = 'NEXT' then
_TDataSet.Next
else if MethodName = 'PRIOR' then
_TDataSet.Prior
else if MethodName = 'CANCEL' then
_TDataSet.Cancel
else if MethodName = 'DELETE' then
_TDataSet.Delete
else if MethodName = 'POST' then
_TDataSet.Post
else if MethodName = 'APPEND' then
_TDataSet.Append
else if MethodName = 'INSERT' then
_TDataSet.Insert
else if MethodName = 'EDIT' then
_TDataSet.Edit
else if MethodName = 'FIELDBYNAME' then
Result := frxInteger(_TDataSet.FieldByName(Caller.Params[0]))
else if MethodName = 'GETFIELDNAMES' then
_TDataSet.GetFieldNames(TStrings(frxInteger(Caller.Params[0])))
else if MethodName = 'FINDFIRST' then
Result := _TDataSet.FindFirst
else if MethodName = 'FINDLAST' then
Result := _TDataSet.FindLast
else if MethodName = 'FINDNEXT' then
Result := _TDataSet.FindNext
else if MethodName = 'FINDPRIOR' then
Result := _TDataSet.FindPrior
else if MethodName = 'FREEBOOKMARK' then
_TDataSet.FreeBookmark(TBookMark(frxInteger(Caller.Params[0])))
{$IFNDEF WIN64}
else if MethodName = 'GETBOOKMARK' then
Result := frxInteger(_TDataSet.GetBookmark)
{$ENDIF}
else if MethodName = 'GOTOBOOKMARK' then
_TDataSet.GotoBookmark(TBookMark(frxInteger(Caller.Params[0])))
else if MethodName = 'LOCATE' then
Result := _TDataSet.Locate(Caller.Params[0], Caller.Params[1], IntToLocateOptions(Caller.Params[2]))
else if MethodName = 'ISEMPTY' then
Result := _TDataSet.IsEmpty
else if MethodName = 'ENABLECONTROLS' then
_TDataSet.EnableControls
else if MethodName = 'DISABLECONTROLS' then
_TDataSet.DisableControls
else if MethodName='CREATE' then
Result := frxInteger(TComponent(Instance).Create(TComponent(frxInteger(Caller.Params[0]))))
else if MethodName='ADDINDEX' then
BsAddIndex(Caller.Params[0], Caller.Params[1],Caller.Params[2])
end
else
if ClassType = TIndexDefs then
begin
_TIndexDefs := TIndexDefs(Instance);
if MethodName='ADD' then
IndexDefsAdd(Caller.Params[0],Caller.Params[1],Caller.Params[2])
end;
end;

function TBsFunctions.GetProp(Instance: TObject; ClassType: TClass;
const PropName: String): Variant;
var
_TField: TField;
_TParam: TParam;
_TDataSet: TBsDataSet;
_TIndexDefs:TIndexDefs;

function FilterOptionsToInt(f: TFilterOptions): Integer;
begin
Result := 0;
if foCaseInsensitive in f then
Result := Result or 1;
if foNoPartialCompare in f then
Result := Result or 2;
end;

begin
Result := 0;
if ClassType = TBsDataSet then
begin
_TDataSet := TBsDataSet(Instance);
if PropName = 'BOF' then
Result := _TDataSet.Bof
else if PropName = 'EOF' then
Result := _TDataSet.Eof
else if PropName = 'FIELDCOUNT' then
Result := _TDataSet.FieldCount
else if PropName = 'FIELDDEFS' then
Result := frxInteger(_TDataSet.FieldDefs)
else if PropName = 'FIELDS' then
Result := frxInteger(_TDataSet.Fields)
else if PropName = 'FILTER' then
Result := _TDataSet.Filter
else if PropName = 'FILTERED' then
Result := _TDataSet.Filtered
else if PropName = 'FILTEROPTIONS' then
Result := FilterOptionsToInt(_TDataSet.FilterOptions)
else if PropName = 'ACTIVE' then
Result := _TDataSet.Active
else if PropName = 'DATA' then
Result := _TDataSet.Data
else if PropName = 'PARAMS' then
Result := frxInteger(_TDataSet.Params)
else if PropName = 'INDEXDEFS' then
Result := frxInteger(_TDataSet.IndexDefs)
else if PropName = 'FILTERCODE' then
Result := _TDataSet.FilterCode
else if PropName = uppercase('FilterLineListText') then
Result := _TDataSet.FilterLineListText
else if PropName = uppercase('FilterLineSQL') then
Result := _TDataSet.FilterLineSQL
else if PropName = 'FBMUSTFILTER' then
Result := _TDataSet.FbMustFilter
else if PropName = 'FBPOST' then
Result := _TDataSet.FbPost
else if PropName = 'FBMULTTABLE' then
Result := _TDataSet.FbMultTable
else if PropName = 'RECORDCOUNT' then
Result := _TDataSet.RecordCount
else if PropName = 'QFDATASETOPENSQL' then
Result := _TDataSet.QFDataSetOpenSQL;
end
end;

procedure TBsFunctions.SetProp(Instance: TObject; ClassType: TClass;
const PropName: String; Value: Variant);
var
_TField: TField;
_TParam: TParam;
_TDataSet: TBsDataSet;

function IntToFilterOptions(i: Integer): TFilterOptions;
begin
Result := [];
if (i and 1) <> 0 then
Result := Result + [foCaseInsensitive];
if (i and 2) <> 0 then
Result := Result + [foNoPartialCompare];
end;

begin
if ClassType = TBsDataSet then
begin
_TDataSet := TBsDataSet(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
ELSE if PropName = 'DATA' then
_TDataSet.Data := Value
else if PropName = 'FILTERCODE' then
_TDataSet.FilterCode := Value
else if PropName = uppercase('FilterLineListText') then
_TDataSet.FilterLineListText := Value
else if PropName = uppercase('FilterLineSQL') then
_TDataSet.FilterLineSQL := Value
else if PropName = 'FBMUSTFILTER' then
_TDataSet.FbMustFilter := Value
else if PropName = 'FBPOST' then
_TDataSet.Fbpost := Value
else if PropName = 'FBMULTTABLE' then
_TDataSet.FbMultTable := Value
else if PropName = 'QFDATASETOPENSQL' then
_TDataSet.QFDataSetOpenSQL := Value;

end
end;

initialization

finalization

end.

fastscript增加三方控件之二的更多相关文章

  1. fastscript增加三方控件

    fastscript增加三方控件 A.关于如何使用第三方控件,增加方法.属性.事件)举例如下: 如:有一控件为edtbutton:TedtButton,我们需要在动态脚本中使用该控件.我们采用如下方法 ...

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

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

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

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

  4. 对百度WebUploader开源上传控件的二次封装,精简前端代码(两句代码搞定上传)

    前言 首先声明一下,我这个是对WebUploader开源上传控件的二次封装,底层还是WebUploader实现的,只是为了更简洁的使用他而已. 下面先介绍一下WebUploader 简介: WebUp ...

  5. PropertyGrid控件由浅入深(二):基础用法

    目录 PropertyGrid控件由浅入深(一):文章大纲 PropertyGrid控件由浅入深(二):基础用法 控件的外观构成 控件的外观构成如下图所示: PropertyGrid控件包含以下几个要 ...

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

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

  7. Xamarin XAML语言教程构建ControlTemplate控件模板 (二)

    Xamarin XAML语言教程构建ControlTemplate控件模板 (二) (2)打开MainPage.xaml文件,编写代码,将构建的控件模板应用于ContentView中.代码如下: &l ...

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

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

  9. Android support library支持包常用控件介绍(二)

    谷歌官方推出Material Design 设计理念已经有段时间了,为支持更方便的实现 Material Design设计效果,官方给出了Android support design library ...

随机推荐

  1. HDU:2586-How far away

    How far away Time limit1000 ms Memory limit32768 kB Problem Description There are n houses in the vi ...

  2. (转)减少oracle sql回表次数 提高SQL查询性能

    要写出高效的SQL,那么必须必须得清楚SQL执行路径,介绍如何提高SQL性能的文章很多,这里不再赘述,本人来谈谈如何从 减少SQL回表次数 来提高查询性能,因为回表将导致扫描更多的数据块. 我们大家都 ...

  3. npm 安装express npm ERR! code UNABLE_TO_VERIFY_LEAF_SIGNATURE

    npm安装总是报错 报错信息: 解决方案: 在命令行输入: npm config set strict-ssl false 设置之后即可安装软件:

  4. ogre3D程序实例解析1-平移旋转与缩放

    接着上篇写 http://www.cnblogs.com/songliquan/p/3294902.html 旋转 这里有必要看一下关于旋转的源代码:    virtual void pitch(co ...

  5. Python中__get__ ,__getattr__ ,__getattribute__用法与区别?

    class C(object): a = 'abc' def __getattribute__(self, *args, **kwargs): print("__getattribute__ ...

  6. python学习-- Django传递数据给JS

    var List = {{ List|safe }};//safe 必须存在

  7. 在Notepad++里配置python环境

    首先在语言里选择Python 然后点击运行,在弹出的对话框里输入: cmd /k cd /d "$(CURRENT_DIRECTORY)" &  python " ...

  8. 设计模式(二 & 三)工厂模式:3-抽象工厂模式

    什么是抽象工厂? 抽象工厂模式,引入了“产品族”的概念. 何为产品族?还是以 设计模式(二)工厂模式:2-工厂方法模式 提到的 Operation 为例. 之前讨论的都是局限于 Operation 这 ...

  9. Linux Shell系列教程之(三)Shell变量

    本文是Linux Shell系列教程的第(三)篇,更多shell教程请看:Linux Shell系列教程 Shell作为一种高级的脚本类语言,也是支持自定义变量的.今天就为大家介绍下Shell中的变量 ...

  10. 【Vjudge】P558E A Simple Task(线段树暴力)

    题目链接 这题……太暴力了吧…… 开二十六棵线段树维护l到r字符i出现的次数,然后修改的时候暴力修改,输出的时候暴力输出……就过了…… 然后我还没想到…… qwq #include<cstdio ...