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

#include <vcl.h>
#pragma hdrstop

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

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

void __fastcall TForm1::Button3Click(TObject *Sender)
{
  CDS->CreateDataSet();
}

void __fastcall TForm1::Button4Click(TObject *Sender)
{
  CDS2->Data = CDS->Data;
}

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

// BeginExample: TParamsAssign
// Method: Classes.TCollection.Assign
// Method: DB.TParams.AssignValues
// Method: DB.TParams.CreateParam

// BeginCode
/*
  This example saves params from a ClientDataSet, alters them
  and restores them.
*/
TParams *SavedParams;

void __fastcall TForm1::SaveParamsClick(TObject *Sender)
{
  // Save the parameters for the TDataSet
  SavedParams->Assign(CDS->Params);
}

void __fastcall TForm1::AlterParamsClick(TObject *Sender)
{
  CDS->Params->CreateParam(ftInteger, "StateParam", ptInput);
  CDS->Params->CreateParam(ftInteger, "MyParam", ptInput);
  for (int i = 0; i < CDS->Params->Count; i++)
	if ((CDS->Params->Items[i]->IsNull) &&
	   (CDS->Params->Items[i]->DataType == ftInteger))
	  // Items is the default property, so you can omit its name
	  CDS->Params->Items[i]->AsInteger = -1;
}

void __fastcall TForm1::RestoreParamsClick(TObject *Sender)
{
  // Restore the parameters to TDataSet
  CDS->Params->AssignValues(SavedParams);
}

#include <memory>       //for STL auto_ptr class

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  // Initialize SavedParams
  static std::auto_ptr<TParams> _SavedParamsCleaner(SavedParams = new TParams());
}
// EndCode
// EndExample: TParamsAssign








