1,2应该问题不大。
3。可以动态设置DSN,这里是一个动态建立Excel DSN的函数,稍改一下你就可以实现Access的。
//////////////////////
const
msg1='创建数据失败!';
DSN='savenight_gps';
function CreateUserDSN(filename: string):Boolean;
implementation
function CreateUserDSN(filename: string):Boolean;
var
reg: TRegistry;
bData: array[0..0] of byte;
systemPath: array[0..254] of char;
begin
GetSystemDirectory(systemPath, 255);
reg := TRegistry.Create;
with regdo
begin
RootKey := HKEY_CURRENT_USER;
if OpenKey('SoftWare/ODBC/ODBC.INI/ODBC Data Sources', true) then
begin
WriteString(DSN, 'Microsoft Excel Driver (*.xls)');
end
else
begin
showmessage(msg1);
result:=false;
exit;
end;
CloseKey;
if OpenKey('SoftWare/ODBC/ODBC.INI/'+DSN, true) then
begin
WriteString('DBQ', filename);
WriteString('Driver', systemPath + '/odbcjt32.dll');
WriteInteger('DriverId', $316);
WriteString('FIL', 'excel 8.0;');
WriteInteger('SafeTransaction', 0);
WriteString('UID', '');
bData[0] := 0;
WriteBinaryData('ReadOnly', bData, 1);
//非只读
end
else
begin
showmessage(msg1);
result:=false;
exit;
end;
CloseKey;
if OpenKey('Software/ODBC/ODBC.INI/'+DSN+'/Engines/Excel', True) then
begin
WriteBinaryData('FirstRowHasNames', bData, 1);
WriteString('ImplicitCommitSync', '');
WriteInteger('MaxScanRows', 8);
WriteInteger('Threads', 3);
WriteString('UserCommitSync', 'Yes');
end
else
begin
showmessage(msg1);
result:=false;
exit;
end;
CloseKey;
Free;
end;
result:=true;
end;