conndb.~pas
来自「用DELPH写的DAO访问模块.有连接池.应用了各种模块,把数据库操作」· ~PAS 代码 · 共 104 行
~PAS
104 行
{*******************************************************}
{ }
{ 数据库连接对象基类 }
{ }
{ 版权所有 (C) 2009 大道网络 }
{ }
{*******************************************************}
unit ConnDB;
interface
uses
Classes, SysUtils, Windows, ADODB, DBTables, DB, Messages, IConnDB, ConnDBConfig, DBStructure;
type
//==============================================================================
// 数据库连接对象基类
// 抽象数据库连接对象 (产品基类)
//==============================================================================
TConnDB = class(TPersistent,IConnDataBase)
private
ConnDBKind: TConnDBKind; //数据库连接方式
ConnDBConfig: TConnDBConfig; //数据库配置参数类
protected
FRefCount: Integer;
pDBConn: TCustomConnection;
//接口必须实现部分
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
//接口
function getDBConnection: TCustomConnection; virtual; abstract;
function ConnfigDBConnection: Boolean; virtual; abstract;
procedure setConnDBKind(pConnDBKind :TConnDBKind);
function getConnDBKind: TConnDBKind;
procedure setConnDBConfig(pConnDBConfig :TConnDBConfig);
function getConnDBConfig: TConnDBConfig;
public
destructor Destroy; override;
published
property pDBConnection: TCustomConnection read getDBConnection;
property pConnDBKind: TConnDBKind read getConnDBKind write setConnDBKind;
property pConnDBConfig: TConnDBConfig read getConnDBConfig write setConnDBConfig;
end;
implementation
function TConnDB.QueryInterface(const IID: TGUID; out Obj): HResult;
begin
if GetInterface(IID, Obj) then
Result := 0
else
Result := E_NOINTERFACE;
end;
function TConnDB._AddRef: Integer;
begin
Result := InterlockedIncrement(FRefCount);
end;
function TConnDB._Release: Integer;
begin
Result := InterlockedDecrement(FRefCount);
if Result = 0 then
Destroy;
end;
procedure TConnDB.setConnDBKind(pConnDBKind :TConnDBKind);
begin
ConnDBKind := pConnDBKind;
end;
function TConnDB.getConnDBKind: TConnDBKind;
begin
Result := ConnDBKind;
end;
procedure TConnDB.setConnDBConfig(pConnDBConfig :TConnDBConfig);
begin
ConnDBConfig := pConnDBConfig;
end;
function TConnDB.getConnDBConfig: TConnDBConfig;
begin
Result := ConnDBConfig;
end;
destructor TConnDB.Destroy;
begin
inherited Destroy;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?