IndexName (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses the IndexName property to sort the records in a client dataset on the Field2 field.

Code

void __fastcall TForm1::Button3Click(TObject *Sender)
{
  // If Active is True, Update removes Fields added in FormCreate
  // and adds the DEFAULT_ORDER and CHANGEINDEX Fields.
  CDS2->Active = False;
  // Get the current available indices.
  CDS2->IndexDefs->Update();
  // Find a field named "Field2".
  for (int I = 0; I < CDS2->IndexDefs->Count; I++)
	if (CDS2->IndexDefs->Items[I]->Fields == "Field2")
	{
	  // Set that index as the current index for the dataset. }
	  CDS2->IndexName = CDS2->IndexDefs->Items[I]->Name;
	}
  CDS2->Active = True;
}

Uses