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. Lazy Load 图片延迟加载(转)

    jQuery Lazy Load 图片延迟加载来源 基于 jQuery 的图片延迟加载插件,在用户滚动页面到图片之后才进行加载. 对于有较多的图片的网页,使用图片延迟加载,能有效的提高页面加载速度. ...

  2. careercup-C和C++ 13.8

    13.8 编写一个智能指针类.智能指针是一种数据类型,一般用模板实现,模拟指针行为的同时还提供自动垃圾回收机制.它会自动记录SmartPointer<T*>对象的引用计数,一旦T类型对象的 ...

  3. debian配置简单的vsftp服务器

    Ubuntu Linux与Windows系统不同,Ubuntu Linux不会产生无用垃圾文件,但是在升级缓存中,Ubuntu Linux不会自动删除这些文件,今天就来说说这些垃圾文件清理方法.  1 ...

  4. php转义和去掉html、php标签函数

    /** * 转义html字符 * * @param string|array $var */function fhtmlspecialchars($var) { if (is_array ( $var ...

  5. famous javascript library.

    https://famo.us/ THE ULTIMATE WEB PLATFORM FOR DEVELOPERS AND DESIGNERS

  6. centos find

    首先你要确定你的软件是什么方式安装?如果不确定,你可知道你的软件名字,用find查找一下在哪个目录find / -name softname

  7. redhat ping不通外网的解决办法

    ping自己和网关都能ping通就是无法ping通外网例如百度: [root@ocdp1 ~]# ping www.baidu.com ping: unknown host www.baidu.com ...

  8. asp.net Hierarchical Data

    Introduction A Hierarchical Data is a data that is organized in a tree-like structure and structure ...

  9. ###STL学习--vector

    点击查看Evernote原文. #@author: gr #@date: 2014-08-11 #@email: forgerui@gmail.com vector的相关问题.<stl学习> ...

  10. ###STL学习--适配器

    点击查看Evernote原文. #@author: gr #@date: 2014-08-24 #@email: forgerui@gmail.com STL中的适配器. ###stl学习 |--迭代 ...