我原用BDE来做程序时,也是用ODBC来连接数据库用到了如下文件
BANTAM.DLL
IDAPI32.DLL
IDBAT32.DLL
IDODBC32.DLL
IDPDX32.DLL
IDSQL32.DLL
然后我在工程文件中写一段动态建立ODBC别名的代码,这样,用户就用不着去设置ODBC了,当然也就不用担心用户误删了别名而运行不了软件了
代码如下
uses
Forms,
windows,
messages,
Registry,
sysUtils,
ShellApi,
...
var
rSysReg, registry1: TRegistry;
SysDir: PChar;
AppPath, Params, Path, DbPath: string;
begin
AppPath := ExtractFilePath(Application.ExeName);
//取得应用程序的当前路径
GetMem(SysDir, 255);
GetSystemDirectory(SysDir, 255);
//取得WINDOWS系统目录
Path := string(SysDir);
registry1 := tregistry.Create;
registry1.RootKey := HKEY_CURRENT_USER;
if registry1.OpenKey('software/odbc/odbc.ini/odbc data sources', true) then
begin
registry1.WriteString('SF', 'Microsoft Access Driver (*.mdb)');
registry1.CloseKey;
end;
if registry1.OpenKey('software/odbc/odbc.ini/SF', true) then
begin
registry1.WriteString('DBQ', apppath + 'SF.mdb');
registry1.WriteString('Driver', path + '/odbcjt32.dll');
registry1.Writeinteger('DriverId', 25);
registry1.writestring('FIL', 'MS Access;');
registry1.WriteInteger('SafeTransactions', 0);
registry1.WriteString('UID', '');
registry1.CloseKey;
end;
if registry1.OpenKey('software/odbc/odbc.ini/SF/Engines/Jet', true) then
begin
registry1.writestring('ImplicitCommitSync', 'Yes');
registry1.writeinteger('MaxBufferSize', 512);
registry1.WriteInteger('PageTimeout', 10);
registry1.writeinteger('Threads', 3);
registry1.WriteString('UserCommitSync', 'Yes');
end;
registry1.CloseKey;
registry1.Free;