BPL 代码:

uDM.pas

unit uDM;

interface

uses
SysUtils, Classes, uIntf, DB, ABSMain; type
TDM = class(TDataModule, IDMSearch)
DS: TDataSource;
DB: TABSDatabase;
Qry: TABSQuery;
procedure DataModuleCreate(Sender: TObject);
procedure DataModuleDestroy(Sender: TObject);
private
{ Private declarations }
public
function Search(ACode: integer): TDataSource;
end; var
DM: TDM; implementation {$R *.dfm} procedure TDM.DataModuleCreate(Sender: TObject);
begin
SetCurrentDir(ExtractFilePath(ParamStr(0)));
DB.DatabaseFileName := ExtractFilePath(ParamStr(0)) + 'Demo.ABS';
DB.Open;
end; procedure TDM.DataModuleDestroy(Sender: TObject);
begin
DB.Close;
end; function TDM.Search(ACode: integer): TDataSource;
begin
with Qry do
begin
Close;
if ACode = -1 then
SQL.Text := 'select * from [DemoTable]'
else
SQL.Text := Format('select * from [DemoTable] where [Code]=%d', [ACode]);
Open;
Result := DS;
end;
end; initialization
RegisterClass(TDM); finalization
UnRegisterClass(TDM); end.

uDM.dfm

object DM: TDM
OldCreateOrder = False
OnCreate = DataModuleCreate
OnDestroy = DataModuleDestroy
Height = 175
Width = 215
object DS: TDataSource
DataSet = Qry
Left = 16
Top = 112
end
object DB: TABSDatabase
CurrentVersion = '5.11 '
DatabaseName = 'Demo'
Exclusive = False
MaxConnections = 500
MultiUser = False
SessionName = 'Default'
Left = 16
Top = 8
end
object Qry: TABSQuery
CurrentVersion = '5.11 '
DatabaseName = 'Demo'
InMemory = False
ReadOnly = False
Left = 16
Top = 64
end
end

DBM.dpk

package DBM;

{$R *.res}
{$ALIGN 8}
{$ASSERTIONS ON}
{$BOOLEVAL OFF}
{$DEBUGINFO ON}
{$EXTENDEDSYNTAX ON}
{$IMPORTEDDATA ON}
{$IOCHECKS ON}
{$LOCALSYMBOLS ON}
{$LONGSTRINGS ON}
{$OPENSTRINGS ON}
{$OPTIMIZATION ON}
{$OVERFLOWCHECKS OFF}
{$RANGECHECKS OFF}
{$REFERENCEINFO ON}
{$SAFEDIVIDE OFF}
{$STACKFRAMES OFF}
{$TYPEDADDRESS OFF}
{$VARSTRINGCHECKS ON}
{$WRITEABLECONST OFF}
{$MINENUMSIZE 1}
{$IMAGEBASE $400000}
{$IMPLICITBUILD ON} requires
rtl,
vcl,
dbrtl,
dclAbsDBd10; contains
uDM in 'uDM.pas' {DM: TDataModule},
untIntf in '..\intf\uIntf.pas'; end.

EXE 代码:

uMain.pas

unit uMain;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,untIntf, StdCtrls, ExtCtrls, Grids, DBGrids, DB; type
TFormMain = class(TForm)
DBGrid1: TDBGrid;
Panel1: TPanel;
LabeledEdit1: TLabeledEdit;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
bplHandle: Cardinal;
DM: IDMSearch;
end; var
FormMain: TFormMain; implementation {$R *.dfm} procedure TFormMain.Button1Click(Sender: TObject);
var
ds: TDataSource;
begin
ds:=DM.Search(StrToIntDef(LabeledEdit1.Text, -1));
DBGrid1.DataSource := ds;
end; procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
DM := nil;
// UnloadPackage(bplHandle);
end; procedure TFormMain.FormCreate(Sender: TObject);
var
c: TClass;
begin
SetCurrentDir(ExtractFilePath(ParamStr(0)));
bplHandle := LoadPackage('DBM.bpl');
c:= GetClass('TDM');
if c <> nil then
DM := TComponentClass(c).Create(Application) as IDMSearch;
end; end.

uMain.dfm

object FormMain: TFormMain
Left = 0
Top = 0
Caption = 'FormMain'
ClientHeight = 237
ClientWidth = 246
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 0
Top = 0
Width = 246
Height = 184
Align = alClient
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
end
object Panel1: TPanel
Left = 0
Top = 184
Width = 246
Height = 53
Align = alBottom
BevelInner = bvRaised
BevelOuter = bvLowered
TabOrder = 1
object LabeledEdit1: TLabeledEdit
Left = 8
Top = 20
Width = 146
Height = 21
EditLabel.Width = 25
EditLabel.Height = 13
EditLabel.Caption = 'Code'
TabOrder = 0
end
object Button1: TButton
Left = 160
Top = 16
Width = 75
Height = 25
Caption = #26597#35810
TabOrder = 1
OnClick = Button1Click
end
end
end

Project1.dpr

program Project1;

uses
Forms,
frmMain in 'uMain.pas' {FormMain},
uIntf in '..\intf\uIntf.pas'; {$R *.res} begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TFormMain, FormMain);
Application.Run;
end.

通用接口单元代码:

uIntf.pas

unit uIntf;

interface

uses
Classes, SysUtils, DB; type
IDMSearch = interface
['{494B4378-A373-4BAD-95D6-49CC12F76ADF}']
function Search(ACode: Integer): TDataSource;
end; implementation end.

用 BPL 封装数据连接的更多相关文章

  1. 帆软报表FineReport中数据连接的JDBC连接池属性问题

    连接池原理 在帆软报表FineReport中,连接池主要由三部分组成:连接池的建立.连接池中连接使用的治理.连接池的关闭.下面就着重讨论这三部分及连接池的配置问题. 1. 连接池原理 连接池技术的核心 ...

  2. python全栈开发day113-DBUtils(pymysql数据连接池)、Request管理上下文分析

    1.DBUtils(pymysql数据连接池) import pymysql from DBUtils.PooledDB import PooledDB POOL = PooledDB( creato ...

  3. SpringBoot整合Druid数据连接池

    SpringBoot整合Druid数据连接池 Druid是什么? Druid是Alibaba开源的的数据库连接池.Druid能够提供强大的监控和扩展功能. 在哪里下载druid maven中央仓库: ...

  4. Programming With Objective-C---- Encapsulating Data ---- Objective-C 学习(三) 封装数据

      Programming with Objective-C Encapsulating Data In addition to the messaging behavior covered in t ...

  5. 帆软报表FineReport中数据连接之Weblogic配置JNDI连接

    1. 制作报表的原理 在帆软报表FineReport设计器中先用JDBC连接到数据库,建立数据库连接,然后用SQL或者其他方法创建数据集,使用数据集制作报表,然后把建立的数据库连接从JDBC连接改成J ...

  6. 帆软报表FineReport中数据连接之Jboss配置JNDI连接

    使用sqlsever 2000数据库数据源来做实例讲解,帆软报表FineReport数据连接中Jboss配置JNDI大概的过程和WEBSPHERE以及WEBLOGIC基本相同,用JDBC连接数据库制作 ...

  7. 帆软报表FineReport中数据连接之Websphere配置JNDI连接

    以oracle9i数据源制作的模板jndi.cpt为例来说明如何在FineReport中的Websphere配置JNDI连接.由于常用服务器的JNDI驱动过大,帆软报表FineReport中没有自带, ...

  8. 帆软报表FineReport中数据连接之Tomcat配置JNDI连接

    1. 问题描述 在帆软报表FineReport中,通过JNDI方式定义数据连接,首先在Tomcat服务器配置好JNDI,然后在设计器中直接调用JNDI的名字,即可成功使用JNDI连接,连接步骤如下: ...

  9. Netbeans 中创建数据连接池和数据源步骤(及解决无法ping通问题)

    1.启动glassfish服务器, 在浏览器的地址栏中输入 http://localhost:4848 2.首先建立JDBC Connection Pools: 3.new 一个Connectio P ...

随机推荐

  1. linux之ubuntu下php环境配置

    本文主要说明如何在Ubuntu下配置PHP开发环境LAMP.   Ubuntu 搭建 php 环境   所谓LAMP:Linux,Apache,Mysql,PHP   安装 Apache2:(注意可以 ...

  2. mysql datetime、date、time、timestamp区别

    我们看看这几个数据库中(mysql.oracle和sqlserver)如何表示时间 mysql数据库:它们分别是 date.datetime.time.timestamp和year.date :“yy ...

  3. 详解 Objective-C 中的 Runtime

    公司项目用到一个三方开源库,里面有个bug,不能改动源码,我想来想去,只能通过runtime这个万能的手段来解决.但是runtime 并不怎么会用,怎么办,马上学习呗.说到runtime,它是Obje ...

  4. 如何真正免费运营推广APP应用

    随着移动终端的迅速普及,各类APP如雨后春笋般涌现出来,但是真正的运营成功的产品却寥寥无几. 从瓜分渠道资源到抢占用户的过程中,很多同行都明显的感觉到,渠道平台所带来的量日益减少,但是刊例价格却一再攀 ...

  5. Activity的启动模式及回退栈的概念

    Activity的启动模式 standard 正常模式 在创建一个新的activity的时候,直接在栈顶创建一个新的activity singleTop 顶部单个 在创建一个新的activity的时候 ...

  6. Js解析json

    var sysModule=[];            var treeJson = <%=(sysModule) %>;            if (treeJson.length ...

  7. Objective-C /iphone开发基础:协议(protocol)

    protocol协议时为了补充Objective-C 只能单继承的缺陷而增加的一个新功能.Objective-C重所有的方法都是虚方法,所以在oc重也就没有关键字 virtual一说,有了协议可以补充 ...

  8. 【Objective-C】2.自定义构造方法和description方法

    1.Student.h 1 #import <Foundation/Foundation.h> 2 3 @interface Student : NSObject { 4 int _age ...

  9. scala学习笔记:理解lazy值

    scala> var counter = 0 counter: Int = 0 scala> def foo = {counter += 1; counter} foo: Int scal ...

  10. Hadoop源代码分析

    http://wenku.baidu.com/link?url=R-QoZXhc918qoO0BX6eXI9_uPU75whF62vFFUBIR-7c5XAYUVxDRX5Rs6QZR9hrBnUdM ...