Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <registry.hpp>
  4. #pragma hdrstop
  5. #include "Unit1.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma resource "*.dfm"
  9. TForm1 *Form1;
  10. //---------------------------------------------------------------------------
  11. __fastcall TForm1::TForm1(TComponent* Owner)
  12.         : TForm(Owner)
  13. {
  14. }
  15. //---------------------------------------------------------------------------
  16. void __fastcall TForm1::Button1Click(TObject *Sender)
  17. {
  18.   AnsiString DataSourceName,FileName,WinSysDir;
  19.   TRegistry *rg;
  20.   char buff[MAX_PATH];
  21. //Get WinSysDir
  22.   GetSystemDirectory(buff,MAX_PATH);
  23.   WinSysDir=buff;
  24.   rg=new TRegistry();
  25. //ODBC Config
  26.   DataSourceName=Edit1->Text.Trim();
  27.   FileName=Edit2->Text.Trim();
  28. //
  29.   rg->RootKey=HKEY_CURRENT_USER;
  30.   rg->OpenKey("\Software\ODBC\ODBC.INI\"+DataSourceName,True);
  31.   rg->WriteString("Driver",WinSysDir+"\odbcjt32.dll");
  32.   rg->WriteString("DBQ",FileName);
  33.   rg->WriteString("Description","Access Data Demo");
  34.   rg->WriteInteger("DriverId",0x00000019);
  35.   rg->WriteString("FIL","MS Access;");
  36.   rg->WriteInteger("SafeTransactions",0);
  37.   rg->WriteString("UID","");
  38.   rg->OpenKey("\Software\ODBC\ODBC.INI\"+DataSourceName+"\Engines\Jet",True);
  39.   rg->WriteString("ImplicitCommitSync","");
  40.   rg->WriteInteger("MaxBufferSize",0x00000800);
  41.   rg->WriteInteger("PageTimeout",0x00000005);
  42.   rg->WriteInteger("Threads",0x00000003);
  43.   rg->WriteString("UserCommitSync","Yes");
  44.   rg->OpenKey("\Software\ODBC\ODBC.INI\ODBC Data Sources",True);
  45.   rg->WriteString(DataSourceName,"Microsoft Access Driver (*.mdb)");
  46. //
  47.   rg->CloseKey();
  48.   rg->Free();
  49. }
  50. //---------------------------------------------------------------------------
  51. void __fastcall TForm1::Button2Click(TObject *Sender)
  52. {
  53.   if(OpenDialog1->Execute())
  54.   {
  55.     Edit2->Text=OpenDialog1->FileName;
  56.   }
  57. }
  58. //---------------------------------------------------------------------------