TParamsAssign (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example saves parameters from a ClientDataSet, alters them, and restores them.

Code

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

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  // Initialize SavedParams.
  static std::auto_ptr<TParams> _SavedParamsCleaner(SavedParams = new TParams());
}

Uses

Personal tools
Assistance