• tms脚本演示代码之一


    本例演示:宿主程序(exe)只有界面的设计,业务规则全部放在脚本文件里面。这个脚本文件是个纯文本文件,可以随意修改。一旦运行宿主程序就会装载脚本文件里面的脚本形式的业务规则。这样,业务规则很容易被修改。

    宿主单元:

    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');   // 执行脚本里面的方法
      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 = 'ÖÐÎÄ (¼òÌå) - Ëѹ·Îå±ÊÊäÈë·¨'
        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

  • 相关阅读:
    QAbstractItemModel使用样例与解析(Model::index使用了createIndex,它会被销毁吗?被销毁了,因为栈对象出了括号就会被销毁)
    更多的人为了追求自己真正热爱的事,甚至会在职业生涯刚开始时拒绝许多高薪工作,这样的人最终都成了真正的赢家。
    MYSQL分库分表之sharding-jdbc第四篇
    MYSQL分库分表之 Sharding-JDBC第三篇
    MySQL分库分表之Sharding-JDBC第二篇
    MySQL分库分表之Sharding-JDBC第一篇
    增加复杂度的12危险信号
    ASP.NET-Core-Web-API-Best-Practices-Guide
    聚合
    浏览器输入www.baidu.com后干啥了-web性能优化指南
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2940959.html
Copyright © 2020-2023  润新知