动态创建数据源问题 Delphi / Windows SDK/APIhttp://www.delphi2007.net/DelphiDB/html/delphi_20061221193009175.html
下面代码是动态创建odbc数据源代码,请问要把下面代码加在那个地方才不会出错,
我加在工程文件里也出错,加在单元文件里也出错,
function getwinsyspath:string;
var
buf:array[0..255]of char;
begin
getsystemdirectory(buf,sizeof(buf));
result:=strpas(buf);
if(result<>'')and(result[length(result)]<>'\') then
result:=result+'\';
end;
function createmdbodbc(aodbcname,amdbname:string):boolean;
var
thereg:tregistry;
begin
thereg:=tregistry.create;
with thereg do
begin
rootkey:=hkey_current_user;
if openkey('software\odbc\odbc.ini\odbc data sources',true) then
writestring(aodbcname,'microsoft access driver(*.mdb)')
else
begin
closekey;
free;
result:=false;
exit;
end;
closekey;
if openkey('software\odbc\odbc.ini\'+aodbcname,true) then
begin
writestring('dbq',amdbname);
writestring('driver',getwinsyspath+'odbcjt32.dll');
writestring('driverID',25);
writestring('fil','ms access');
writestring('safetransactions',0);
writestring('uid','');
end else begin
closekey;
free;
result:=false;
exit;
end;
closekey;
if openkey('software\odbc\odbc.ini\'+aodbcname+'\engines\jet',true) then
begin
writestring('implicitcommitsyne','');
writestring('maxbuffersize',2048);
writestring('pagetimeout',5);
writestring('threads',3);
writestring('usercommitsync','yes');
end else begin
closekey;
free;
result:=false;
exit;
end;
closekey;
free;
result:=true;
end;
end;
报什么错?看看是否少引用Registry单元之类...