我用 InstallShield6做了一个安装程序,其中加入了BDE,BDE Alias,PATH 
和TYPE , 但是将安装程序安装后,数据源并没有加入到ODBC中去,请问,如何将数据源自动加入到ODBC中。

解决方案 »

  1.   

    function CreateDataSource(tmpDBpath:string;DataSource:string):boolean;//tmpdbpth为数据库路径,//DataSource为数据源名字,你在installshield中写入相应的键值即可
    var  wReg:TRegistry;
         tmppath:array[0..255] of char;
         syspath:string;
    const
        ProMsg='测试ODBC数据源';
    begin
      GetSystemDirectory(tmppath,255);
      syspath:=strpas(tmppath);
      wReg:=TRegistry.Create;
       with wReg do
       begin
         RootKey:=HKEY_LOCAL_MACHINE;
          if OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources',true) then
             writestring(DataSource,'microsoft visual foxpro driver')
          else
             begin
               application.MessageBox('ODBC初始化错误!',ProMsg,MB_OK) ;
               result:=false;
               EXIT;
               end;
               closekey;
      if openkey('Software\ODBC\ODBC.INI\'+DataSource,true)then
        begin
         WriteString('backgroundFetch','yes');
         WriteString('collate','STROKE');
         WriteString('Deleted','yes');
         WriteString('Description','vfp数据源');
         WriteString('Driver',SysPath+'\vfpodbc.dll');
         WriteString('exclusive','no');
         WriteString('SetNoCountOn','no');
         WriteString('SourceDB',tmpDBpath);
         WriteString('sourceType','DBF');
         end
         else
         begin
          application.MessageBox('ODBC初始化错误!',ProMsg,mb_ok);
          result:=false;
          EXIT;
          end;
          closekey;
      end;
     result:=true;
     end;
      

  2.   

    写注册表项,即InstallShield中的key项
      

  3.   

    在Resource中的Registry Sets中对应的注册表键值中建立
      

  4.   

    不过还有一个问题:为什么在我的delphi中声明变量TRegistry,程序提示出错:
    unrecognize identifier.难道我的delphi安装的不全,可是我是完全安装的呀,
    请问这是为什么?
      

  5.   

    出错信息为:[Error] Undeclared identifier: 'TRegistry' , 我是完全安装,
    这是为什么?