//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "ClientDataSetAddIndex.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  CDS2->LoadFromFile("../CDS.XML");
}

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  CDS2->SaveToFile("../CDS.XML", dfXML);
}

void __fastcall TForm1::Button5Click(TObject *Sender)
{
  CDS2->Close();
}

// BeginExample: ClientDataSetAddIndex
// Method: DBClient.TCustomClientDataSet.AddIndex

// BeginCode
/*
The code below creates a new case-insensitive index at
runtime 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.
*/

void __fastcall TForm1::QuickIndexClick(TObject *Sender)
{
  if ((!Edit1->Text.IsEmpty()) &&
	 CDS2->Fields->FindField(Edit1->Text))
  {
	TIndexOptions opts;
	opts << ixCaseInsensitive;
	CDS2->AddIndex(Edit1->Text + "Index", Edit1->Text, opts, "", "",0);
	CDS2->IndexName = Edit1->Text + "Index";
  }
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  TFieldDefs *pDefs = CDS2->FieldDefs;
  TFieldDef *pDef = pDefs->AddFieldDef();
  pDef->DataType = ftInteger;
  pDef->Name = "Field1";

  pDef = pDefs->AddFieldDef();
  pDef->DataType = ftString;
  pDef->Size = 10;
  pDef->Name = "Field2";

  TIndexDef *pIDef = CDS2->IndexDefs->AddIndexDef();
  pIDef->Fields = "Field1";
  pIDef->Name = "IntIndex";

  CDS2->CreateDataSet();
}
// EndCode
// EndExample: ClientDataSetAddIndex
//---------------------------------------------------------------------------

