C++Builder Personal で DAO

テーブル一覧を取得する


void __fastcall TForm1::Button1Click(TObject *Sender)
{
//表示用コントロールをクリア
ListBox1->Items->Clear();
ListBox2->Items->Clear();

Variant de = Variant::CreateObject("DAO.DBEngine.36");

//Edit3 に mdbファイル名を入力
Variant db = de.Exec(Function("OpenDatabase")<<Edit3->Text<<false<<false);
Variant tds = db.Exec(Function("TableDefs"));

const int dbSystemObject = -2147483646;
const int dbHiddenObject = 1;

for (int i=0;i<tds.Exec(PropertyGet("Count"));i++)
{
Variant td = db.Exec(PropertyGet("TableDefs")<<i);

if (td.Exec(PropertyGet("Attributes")) & dbSystemObject)
//システムオブジェクトは ListBox2 に表示
ListBox2->Items->Add(td.Exec(PropertyGet("Name")));

else if (td.Exec(PropertyGet("Attributes")) & dbHiddenObject)
//隠しオブジェクトは ListBox2 に表示
ListBox2->Items->Add(td.Exec(PropertyGet("Name")));

else
//通常のテーブルを ListBox1 に表示
ListBox1->Items->Add(td.Exec(PropertyGet("Name")));
}

db.Exec(Procedure("Close"));
}