IndexName (Delphi)

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

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;

Uses