ClientDataSetAddIndex (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The code below creates a new case-insensitive index at run time and then sorts the client dataset using that index. The user specifies the field on which to sort the client dataset in an edit control.

Code

{$IFNDEF UNICODE}
uses SwSystem;
{$ENDIF}

procedure TForm1.QuickIndexClick(Sender: TObject);
begin
  if (Edit1.Text <> '') and
     (CDS.Fields.FindField(Edit1.Text) <> nil) then
  begin
    CDS.AddIndex(Edit1.Text + 'Index', Edit1.Text, [ixCaseInsensitive],'','',0);
    CDS.IndexName := Edit1.Text + 'Index';
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
{$IFDEF UNICODE}
  CDS.LoadFromFile(GetCurrentDir + '\CDS.XML');
{$ELSE}
  CDS.LoadFromFile(gsAppPath + 'CDS.XML');
{$ENDIF}
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
{$IFDEF UNICODE}
  CDS.SaveToFile(GetCurrentDir + '\CDS.XML', dfXML);
{$ELSE}
  CDS.SaveToFile(gsAppPath + 'CDS.XML', dfXML);
{$ENDIF}
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  CDS.CreateDataSet;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  CDS.Close;
end;

Uses

See Also

Personal tools
RAD Studio 10.2 Tokyo
Assistance