RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TClientDataSet.IndexName Property

Identifies an index for the client dataset.

Pascal
property IndexName: Widestring;
C++
__property BSTR IndexName;

Use IndexName to specify an alternative index for a client dataset.If IndexName is empty, the dataset's sort order is based on the IndexFieldNames property or on its default ordering in the data packet. Default ordering is determined by the predefined index, DEFAULT_ORDER. 

If IndexName contains a valid index name, then that index is used to determine sort order of records.

Note: IndexFieldNames and IndexName are mutually exclusive. Setting one clears the other.
 

C++ Examples: 

 

/*
This example uses the IndexName property to sort the records
in a client dataset on the Field2 field.
*/
void __fastcall TForm1::Button3Click(TObject *Sender)
{
  // If Active is True, Update will remove Fields added in FormCreate
  // and add 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;
}

 

Delphi Examples: 

{
This example uses the IndexName property to sort the records
in a client dataset on the Field2 field.
}
procedure TForm1.Button3Click(Sender: TObject);
var
  I : Integer;
begin
  // If Active is True, Update will remove Fields added in FormCreate
  // and add the DEFAULT_ORDER and CHANGEINDEX Fields
  CDS2.Active := False;
  { Get the current available indices }
  CDS2.IndexDefs.Update;
  { Find a field named 'Field2' }
  for I := 0 to CDS2.IndexDefs.Count - 1 do
    if CDS2.IndexDefs.Items[I].Fields = 'Field2' then
    begin
      { set that index as the current index for the dataset}
      CDS2.IndexName := CDS2.IndexDefs.Items[I].Name;
    end;
  CDS2.Active := True;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!