用Session创建表别名。
用TQuery,CREATE语句创建表。
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString Dir;
AnsiString S;
TQuery *AQuery;
try{
Dir = ExtractFilePath(ParamStr(0)) + "DATA//";
ForceDirectories(Dir);
Session->AddStandardAlias("TEST", Dir, "PARADOX");
Session->SaveConfigFile();
AQuery = new TQuery(this);
try{
AQuery->DatabaseName = "TEST";
S = "CREATE TABLE /"TESTTBL.DB/" ("
" 索引 AUTOINC,"
" 姓名 VARCHAR(40),"
" 地址 VARCHAR(60),"
" 电话 VARCHAR(20),"
" 电子邮件 VARCHAR(40),"
" PRIMARY KEY (索引))";
AQuery->Close();
AQuery->SQL->Clear();
AQuery->SQL->Add(S);
AQuery->ExecSQL();
}
__finally{
delete AQuery;
}
}
catch (...){
}
}