tms脚本演示代码之一
本例演示:宿主程序(exe)只有界面的設(shè)計(jì),業(yè)務(wù)規(guī)則全部放在腳本文件里面。這個(gè)腳本文件是個(gè)純文本文件,可以隨意修改。一旦運(yùn)行宿主程序就會(huì)裝載腳本文件里面的腳本形式的業(yè)務(wù)規(guī)則。這樣,業(yè)務(wù)規(guī)則很容易被修改。
?
宿主單元:
unit Unit1;
interface
uses
? Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
? Dialogs, atScript, atPascal, StdCtrls, GridsEh, DBGridEh, DB,
? ADODB, ExtCtrls, DBCtrls, Buttons;
type
? TForm1 = class(TForm)
??? scripter: TatPascalScripter;
??? DataSource1: TDataSource;
??? ADOTable1: TADOTable;
??? DBGridEh1: TDBGridEh;
??? DBNavigator1: TDBNavigator;
??? Panel1: TPanel;
??? procedure FormCreate(Sender: TObject);
? private
??? { Private declarations }
? public
??? { Public declarations }
? end;
var
? Form1: TForm1;
implementation
{$R *.dfm}
uses ap_Classes;
procedure TForm1.FormCreate(Sender: TObject);
begin
? Scripter.AddComponents(Self);??????????????????// 讓腳本可以訪問宿主的對象
? scripter.AddComponents(DataSource1);
? scripter.AddComponents(ADOTable1);
? scripter.AddComponents(DBGridEh1);
? scripter.AddComponents(DBNavigator1);
? scripter.AddComponent(Panel1);
? Scripter.AddEnumeration(TypeInfo(TAlign));???? //?增加支持枚舉型
? Scripter.AddLibrary(TatClassesLibrary);?????????? //?增加支持TNotifyEvent
? scripter.SourceCode.LoadFromFile(ExtractFilePath(Application.ExeName) + '1.txt');?? // 裝載腳本文件
? scripter.ExecuteSubroutine('GetDataSet');???// 執(zhí)行腳本里面的方法
? scripter.ExecuteSubroutine('SetEvent');
end;
end.
?
腳本文件(1.txt):
procedure GetDataSet;
begin
? AdoTable1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb;Persist Security Info=False';
? AdoTable1.TableName := 't1';
? AdoTable1.Active := True;
? DBGridEh1.DataSource := DataSource1;
? DataSource1.DataSet := AdoTable1;
? DBNavigator1.DataSource := DataSource1;
? DBNavigator1.flat := true;
? DBGridEh1.flat := true;
? dbgrideh1.align := alclient;
end;
procedure Panel1Click(Sender);
begin
? ShowMessage('welcome to use scripter');
end;
procedure SetEvent;
begin
? panel1.Caption := 'welcome';
? panel1.onClick := 'Panel1Click';
end;
?
宿主窗體:
object Form1: TForm1
? Left = 338
? Top = 170
? Width = 511
? Height = 379
? Caption = 'Form1'
? Color = clBtnFace
? Font.Charset = DEFAULT_CHARSET
? Font.Color = clWindowText
? Font.Height = -11
? Font.Name = 'MS Sans Serif'
? Font.Style = []
? OldCreateOrder = False
? OnCreate = FormCreate
? PixelsPerInch = 96
? TextHeight = 13
? object DBGridEh1: TDBGridEh
??? Left = 64
??? Top = 57
??? Width = 329
??? Height = 216
??? Align = alCustom
??? Flat = False
??? FooterColor = clWindow
??? FooterFont.Charset = DEFAULT_CHARSET
??? FooterFont.Color = clWindowText
??? FooterFont.Height = -11
??? FooterFont.Name = 'MS Sans Serif'
??? FooterFont.Style = []
??? ImeName = '?D?? (?òì?) - ??1·??±êê?è?·¨'
??? TabOrder = 0
??? TitleFont.Charset = DEFAULT_CHARSET
??? TitleFont.Color = clWindowText
??? TitleFont.Height = -11
??? TitleFont.Name = 'MS Sans Serif'
??? TitleFont.Style = []
? end
? object DBNavigator1: TDBNavigator
??? Left = 0
??? Top = 0
??? Width = 503
??? Height = 25
??? Align = alTop
??? TabOrder = 1
? end
? object Panel1: TPanel
??? Left = 0
??? Top = 306
??? Width = 503
??? Height = 41
??? Align = alBottom
??? Caption = 'Panel1'
??? TabOrder = 2
? end
? object scripter: TatPascalScripter
??? SaveCompiledCode = False
??? ShortBooleanEval = False
??? LibOptions.SearchPath.Strings = (
????? '$(CURDIR)'
????? '$(APPDIR)')
??? LibOptions.SourceFileExt = '.psc'
??? LibOptions.CompiledFileExt = '.pcu'
??? LibOptions.UseScriptFiles = False
??? Left = 48
??? Top = 56
? end
? object DataSource1: TDataSource
??? Left = 88
??? Top = 56
? end
? object ADOTable1: TADOTable
??? Left = 128
??? Top = 56
? end
end
總結(jié)
以上是生活随笔為你收集整理的tms脚本演示代码之一的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 逾期上征信后如何补救 怎么处理逾期后上征
- 下一篇: 放唐骏一马吧