RecordCount (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

Reads through all records in the Customers table. Updates the ProgressBar accordingly.

Code

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  ProgressBar1->Min = 0;
  ProgressBar1->Max = Customers->RecordCount;
  Customers->First();
  for (int i = ProgressBar1->Min; i <= ProgressBar1->Max; i++)
  {
    ProgressBar1->Position = i;
	Customers->Next();
	// Do something with the current record.
  }
}

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  Customers = new TTable(Form1); // The owner will clean this up.
  Customers->Active = false; // The Table component must not be active.
  Customers->DatabaseName = "DBDEMOS";
  Customers->TableType = ttParadox;
  Customers->TableName = "CustInfo";
  Customers->Active = False;
  if (Customers->Exists) // Do not overwrite an existing table.
  {
	Customers->Close();
	Customers->DeleteTable();
  }
  // The Table component must not be active.
  // First, describe the type of table and give it a name.
  // Next, describe the fields in the table.
  Customers->FieldDefs->Clear();
  TFieldDef *pNewDef = Customers->FieldDefs->AddFieldDef();
  pNewDef->Name = "Field1";
  pNewDef->DataType = ftInteger;
  pNewDef->Required = true;
  pNewDef = Customers->FieldDefs->AddFieldDef();
  pNewDef->Name = "Field2";
  pNewDef->DataType = ftString;
  pNewDef->Size = 30;
  // Next, describe any indexes.
  Customers->IndexDefs->Clear();
  /* The first index has no name because it is a Paradox primary key. */
  Customers->IndexDefs->Add("","Field1", TIndexOptions() <<ixPrimary << ixUnique);
  Customers->IndexDefs->Add("Fld2Index","Field2", TIndexOptions() << ixCaseInsensitive);
  // Now that you have specified what you want, create the table.
  Customers->CreateTable();
  Customers->Active = True;
  for (int i = 1; i <= 20; i++)
	Customers->AppendRecord(ARRAYOFCONST((i*111, i*222)));
  DS2->DataSet = Customers;
  DBGrid2->DataSource->DataSet = Customers;
  Customers->Active = True;
}

Uses

Personal tools
Assistance