📄 conndb.pas
字号:
//-------------------------------------------------------------------------
// 数据库连接对象基类
//1.抽象数据库连接对象 (产品基类)
//
//
//-------------------------------------------------------------------------
unit ConnDB;
interface
uses
Classes, SysUtils, Windows, ADODB, DBTables, DB, Messages, IConnDB, ConnDBConfig,
DataStructureUnit;
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -