C++Builder Tips


DAOのバージョン取得


DAOのバージョンをレジストリから取得するサンプルです。


//---------------------------------------------------------------------------

#include <vcl.h>
#include <Registry.hpp>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

//---------------------------------------------------------------------------
AnsiString GetDAODBEngine()
{
  bool bRet = false;

  TRegistry *reg = new TRegistry();

  reg->RootKey = HKEY_CLASSES_ROOT;
  bRet = reg->OpenKey("DAO.DBEngine.36",false);
  if (bRet){
    reg->CloseKey();
    reg->Free();
    return "DAO.DBEngine.36";
  }
  bRet = reg->OpenKey("DAO.DBEngine.35",false);
  if (bRet){
    reg->CloseKey();
    reg->Free();
    return "DAO.DBEngine.35";
  }
  bRet = reg->OpenKey("DAO.DBEngine",false);
  if (bRet){
    reg->CloseKey();
    reg->Free();
    return "DAO.DBEngine";
  }

  Application->MessageBox("DAOが見つかりません。",
               Application->Title.c_str(),
               MB_OK | MB_ICONSTOP);

  reg->CloseKey();
  reg->Free();
  return "";
}

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  ShowMessage(GetDAODBEngine());
}
//---------------------------------------------------------------------------


DownLoad bcbtips081.lzh 4KB(BCB5)