Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include <registry.hpp>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- AnsiString DataSourceName,FileName,WinSysDir;
- TRegistry *rg;
- char buff[MAX_PATH];
- //Get WinSysDir
- GetSystemDirectory(buff,MAX_PATH);
- WinSysDir=buff;
- rg=new TRegistry();
- //ODBC Config
- DataSourceName=Edit1->Text.Trim();
- FileName=Edit2->Text.Trim();
- //
- rg->RootKey=HKEY_CURRENT_USER;
- rg->OpenKey("\Software\ODBC\ODBC.INI\"+DataSourceName,True);
- rg->WriteString("Driver",WinSysDir+"\odbcjt32.dll");
- rg->WriteString("DBQ",FileName);
- rg->WriteString("Description","Access Data Demo");
- rg->WriteInteger("DriverId",0x00000019);
- rg->WriteString("FIL","MS Access;");
- rg->WriteInteger("SafeTransactions",0);
- rg->WriteString("UID","");
- rg->OpenKey("\Software\ODBC\ODBC.INI\"+DataSourceName+"\Engines\Jet",True);
- rg->WriteString("ImplicitCommitSync","");
- rg->WriteInteger("MaxBufferSize",0x00000800);
- rg->WriteInteger("PageTimeout",0x00000005);
- rg->WriteInteger("Threads",0x00000003);
- rg->WriteString("UserCommitSync","Yes");
- rg->OpenKey("\Software\ODBC\ODBC.INI\ODBC Data Sources",True);
- rg->WriteString(DataSourceName,"Microsoft Access Driver (*.mdb)");
- //
- rg->CloseKey();
- rg->Free();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- if(OpenDialog1->Execute())
- {
- Edit2->Text=OpenDialog1->FileName;
- }
- }
- //---------------------------------------------------------------------------