odbc只要写注册表就行了!
//创建ODBC
function Tmainform.createodbc(aliasname,mdbpath:string):boolean;
function getsyspath:string;
var
PText : array[0..255] of Char;
laengde : integer;
begin
laengde:=GetSystemDirectory(PText, MAX_PATH);
result:= copy(PText, 1, laengde);
end;
var
registerTemp : TRegistry;
begin
result:=True;
registerTemp := TRegistry.Create;
with registerTempdo
begin
RootKey:=HKEY_LOCAL_MACHINE;
if OpenKey('Software/ODBC/ODBC.INI/ODBC Data Sources',True) then
begin
if not ValueExists(aliasname) then
begin
WriteString(aliasname,'Microsoft Access Driver (*.mdb)');
CloseKey;
if OpenKey('Software/ODBC/ODBC.INI/'+aliasname,True) then
begin
WriteString('Description',Loadstr(1009));
WriteString('Driver',Getsyspath+'/odbcjt32.dll');
WriteInteger('DriverId',25);
WriteString('FIL','Ms Access;');
WriteInteger('SafeTransaction',0 );
WriteString('UID','');
end;
CloseKey;
if OpenKey('Software/ODBC/ODBC.INI/'+aliasname+'/Engines/Jet',True) then
begin
WriteString( 'ImplicitCommitSync', 'Yes' );
WriteInteger( 'MaxBufferSize', 512 );
WriteInteger( 'PageTimeout', 10 );
WriteInteger( 'Threads', 3 );
WriteString( 'UserCommitSync', 'Yes' );
end;
CloseKey;
end
else
begin
CloseKey;
if OpenKey('Software/ODBC/ODBC.INI/'+aliasname,False) then
WriteString('DBQ',mdbpath)
else
result:=false;
CloseKey;
end;
end;
Free;
end;
end;