安装时能够选择服务器ip,但是比较复杂
如果你用的是installshield,必须在相关脚本里写上好长一段程序,才能完成你说的要求,但是如果你选择做个小程序(比如初始化),在那里肯定要容易的多,也许这也是懒吧,但也一定能完成你说的要求!!

解决方案 »

  1.   

    何必这么麻烦?在设计时不使用ODBC连接,用Database 控制程序的连接,使用sql link. 在Tdatabase的参数server name中设置好您的database server的IP不就行了吗?
      

  2.   

    使用ODBC,下面是我以前写的例子,这里是工程文件的源代码:var
      registerTemp : TRegistry;
      DriverStr:String;
      TcsKeyValue:String;
      TCSBCAODBC:Boolean;begin  registerTemp := TRegistry.Create; //建立一个Registry实例
      with registerTemp do
      begin
        RootKey:=HKEY_LOCAL_MACHINE; //设置根键值为HKEY_LOCAL_MACHINE    {检测系统是否注册}
        TcsKeyValue:='False';
        if OpenKey('Software\TCSBCASystem',False) then
          if ValueExists('TCSBCA') then
            TcsKeyValue:=ReadString('TCSBCA');
        CloseKey;    {如果系统没有注册}
        if TcsKeyValue='False' then
        begin
          {检测系统是否有SQL Server的ODBC驱动程序}
          if openkey('Software\ODBC\ODBCINST.INI\ODBC Drivers',false) then
          begin
            if not ValueExists('SQL Server') then
            begin
              ShowMessage('系统中没有装入SQL Server的ODBC驱动程序,无法启动程序');
              Closekey;
              halt;
            end;
            CloseKey;
          end
          else
          begin
            ShowMessage('系统注册表问题,无法启动程序');
            CloseKey;
            halt;
          end;      {读取SQL Server的驱动程序的存放位置}
          if Openkey('Software\ODBC\ODBCINST.INI\SQL Server',false) then
            DriverStr:=ReadString('Driver')
          else
          begin
            ShowMessage('读取系统中SQL Server的ODBC驱动程序有误,导致无法加载启动程序');
            Closekey;
            halt;
          end;
          CloseKey;      {检测系统是否创建TCSBCA_ODBC}
          if OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources',False) then
            if ValueExists('TCSBCA_ODBC1') then
              TCSBCAODBC:=True
            else
              TCSBCAODBC:=False;
          CloseKey;
          {创建TCSBCA_ODBC}      if not TCSBCAODBC then
            if OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources',True) then
            begin
               WriteString( 'TCSBCA_ODBC', 'SQL Server' );
               CloseKey;
            end
            else
            begin
              ShowMessage('写入系统注册表数据错误,无法加载启动程序');
              Closekey;
              halt;
            end;      if not TCSBCAODBC then
          begin
            if OpenKey('Software\ODBC\ODBC.INI\TCSBCA_ODBC',True) then
            begin
              WriteString( 'Database', 'TCSBCA_DB' );//指定数据库
              WriteString( 'Description', 'TCSBCA系统SQL Server数据源' ); //数据源描述
              //驱动程序DLL文件,根据系统安装的目录不同而不同。
              WriteString( 'Driver', DriverStr ); //驱动程序
              WriteString( 'LastUser', 'sa' );
              WriteString( 'Server', '(local)' );
              TCSBCAODBC:=True ;
              CloseKey;
            end
            else
            begin
              ShowMessage('写入系统注册表数据错误,无法加载启动程序');
              Closekey;
              halt;
            end;
          end;
          {向系统注册表写入系统注册信息}
          if OpenKey('Software\TCSBCASystem',True) then
          begin
            WriteString('TCSBCA','True');
            CloseKey;
          end
          else
          begin
            ShowMessage('写入系统注册表数据错误,无法加载启动程序');
            Closekey;
            halt;
          end;    end;  end;  if not DirectoryExists('Photo') then
      begin
        if not CreateDir('Photo') then
        begin
          ShowMessage('因无法创建 Photo 目录导致无法启动程序');
          halt;
        end;
      end;  if not DirectoryExists('StudentPhoto') then
      begin
        if not CreateDir('StudentPhoto') then
        begin
          ShowMessage('因无法创建 StudentPhoto 目录导致无法启动程序');
          halt;
        end;
      end;  if Not FileExists(ExtractFilePath(Application.ExeName)+'LocalMess.Px') then
      begin
        ShowMessage('重要数据文件丢失,无法启动程序');
        halt;
      end;  Application.Initialize;
      Application.CreateForm(TMainWindows, MainWindows);
      Application.Run;end.