Manage() provides data management functionality for your application and/or process.
Below is the code for Manage():
//---------------------------------------------------------------------------
void TForm1::Manage()
{
Add_CustomerMaster_Records();
Display_Records();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnUpdateClick(TObject *Sender)
{
Update_CustomerMaster_Record();
Display_Records();
}
//---------------------------------------------------------------------------
void TForm1::Add_CustomerMaster_Records()
{
int counter;
try
{
Delete_Records(TabCustMast);
for (counter=0; counter < 4; counter++)
{
// clear the record buffer
TabCustMast->ActiveRecord->Clear();
// populate the record buffer
TabCustMast->ActiveRecord->SetFieldAsString(0, AnsiString(cm_data[counter][0]));
TabCustMast->ActiveRecord->SetFieldAsString(1, AnsiString(cm_data[counter][1]));
TabCustMast->ActiveRecord->SetFieldAsString(2, AnsiString(cm_data[counter][2]));
TabCustMast->ActiveRecord->SetFieldAsString(3, AnsiString(cm_data[counter][3]));
TabCustMast->ActiveRecord->SetFieldAsString(4, AnsiString(cm_data[counter][4]));
TabCustMast->ActiveRecord->SetFieldAsString(5, AnsiString(cm_data[counter][5]));
TabCustMast->ActiveRecord->SetFieldAsString(6, AnsiString(cm_data[counter][6]));
// write the record
TabCustMast->ActiveRecord->Write();
}
}
catch (ECtError &E)
{
Application->ShowException(&E);
}
}
//---------------------------------------------------------------------------
void TForm1::Delete_Records(TCtTable* ATable)
{
try
{
while (ATable->ActiveRecord->First())
{
ATable->ActiveRecord->Delete();
}
}
catch (ECtError &E)
{
Application->ShowException(&E);
}
}
//---------------------------------------------------------------------------
void TForm1::Update_CustomerMaster_Record()
{
AnsiString str;
try
{
str = "1003";
TabCustMast->Lock(CTLOCK_WRITE_BLOCK);
TabCustMast->ActiveRecord->Clear();
TabCustMast->ActiveRecord->SetFieldAsString(0, str);
if (TabCustMast->ActiveRecord->Find(CTFIND_EQ))
{
str = "KEYON DOOLING";
TabCustMast->ActiveRecord->SetFieldAsString(4, str);
TabCustMast->ActiveRecord->Write();
}
Application->MessageBox("Press any key to unlock record", "Warning");
TabCustMast->Unlock();
}
catch (ECtError &E)
{
Application->ShowException(&E);
}
}
//---------------------------------------------------------------------------
void TForm1::Display_Records()
{
int ARow, ACol;
AnsiString AField;
StringGrid1->RowCount = 2;
// display the field names
for (ACol = 0; ACol <= 4; ACol++)
StringGrid1->Cells[ACol][0] = TabCustMast->Fields[ACol]->Field;
// read all fields and display on grid
ARow = 0;
if (TabCustMast->ActiveRecord->First())
do
{
if (ARow > 0)
StringGrid1->RowCount = StringGrid1->RowCount + 1;
for (ACol = 0; ACol <= 4; ACol++)
{
TabCustMast->ActiveRecord->GetFieldAsString(ACol, AField);
StringGrid1->Cells[ACol][(ARow + 1)] = AField;
}
ARow++;
}
while (TabCustMast->ActiveRecord->Next());
}