st.str().c_str();
//范例二
void TDataModuleEmployee::FullReport(const char *title)
{
Report.header(title);
Report << sformat( "Employee #%2d: %s%s\n", TableAllRefnum->Value, TableAllName->Text.c_str(),
TableAllManagerFlag->Value ?"(Manager)" : "" ) << " Address: " <<
TableAllAddress->Text.c_str() << endl << " " << TableAllCityProvZip->Text.c_str() <<
endl << " " << NameCountry(TableAllCanada->Value) << endl;
Report.footer();
}
检查表是否已打开
void TData::CheckEdit()
{
for(int i=0; i < ComponentCount; i++)
{
if(dynamic_cast(Components[i]))
{
if(((TTable*)Components[i])->State == dsEdit)
{
String s = "Table " + Components[i]->Name + " is in edit mode" "\rWould you like to post it before entering new task?";
if(MessageBox(NULL,s.c_str(),"Table in Edit Mode",MB_YESNO | MB_ICONINFORMATION) == IDYES)
((TTable*)Components[i])->Post();
else
((TTable*)Components[i])->Cancel();
}
}
}
}
表的状态操作
//关闭已打开的表并将他们恢复成初始状态。
void TData::MyTables(TForm * sender)
{
int i;
TTable * Table;
bool *active = new bool[MyClass->ComponentCount];//在动态数组中存放每个表的初始状态,然后关闭所有的表
for(i = 0; i < MyClass->ComponentCount; i++)
{
try
{
if((Table = dynamic_cast(MyClass->Components[i])) != NULL)
{
active[i] = Table->Active;
Table->Active = false;
}
}
catch(...) {}; //异常应该只来自于dynamic cast...
}
for(i = 0; i < MyClass->ComponentCount; i++)
{
try
{
if((Table = dynamic_cast(MyClass->Components[i])) != NULL)
{
if(Table->DatabaseName != OPTARDatabase->DatabaseName)
continue;
DBIResult result = DBIERR_NONE + 1;
while(result != DBIERR_NONE) //若希望的话,这样允许用户重试!
{
result = DbiPackTable (OPTARDatabase->Handle,NULL,Table->TableName.c_str(),NULL, true);
if(result != DBIERR_NONE)
{
AnsiString rsltText = "Unable to pack " + Table->TableName + "." ;
char rslt[DBIMAXMSGLEN + 1];
DbiGetErrorString(result, rslt) rsltText += ". Try again?";
if(Application->MessageBox(rsltText.c_str(), "Error!",MB_YESNO) != IDYES)
break;
}
}
}
}
catch (...) {}; //异常应该只来自于dynamic cast...
}
// 将所有的表设回初始状态。
for(i = 0; i < MyClass->ComponentCount; i++)
{
try
{
if((Table = dynamic_cast(MyClass->Components[i])) != NULL)
Table->Active = active[i];
}
catch(...) {};
}
delete []active;
}
改变PageControl的标签
void _
|