RAD Studio VCL Reference
|
Creates a new field parameter object and inserts it into the Items list.
function CreateParam(FldType: TFieldType; const ParamName: string; ParamType: TParamType): TParam;
__fastcall TParam CreateParam(TFieldType FldType, const AnsiString ParamName, TParamType ParamType);
Call CreateParam to instantiate a new TParam object and add it to the Items managed by this TParams object. Specify the field type of the new parameter as the value of FldType, specify the name of the parameter as the value of ParamName, and specify the type of parameter as the value of ParamType.
C++ Examples:
/* 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()); }
Delphi Examples:
{ This example saves params from a ClientDataSet, alters them and restores them. } var SavedParams: TParams; procedure TForm1.SaveParamsClick(Sender: TObject); begin { Save the parameters for the TDataSet } SavedParams.Assign(CDS.Params); end; procedure TForm1.AlterParamsClick(Sender: TObject); var I : Integer; begin CDS.Params.CreateParam(ftInteger, 'StateParam', ptInput); CDS.Params.CreateParam(ftInteger, 'MyParam', ptInput); for I := 0 to CDS.Params.Count - 1 do if (CDS.Params.Items[I].IsNull) and (CDS.Params.Items[I].DataType = ftInteger) then { Items is the default property, so you can omit its name } CDS.Params[I].AsInteger := -1; end; procedure TForm1.RestoreParamsClick(Sender: TObject); begin { Restore the parameters to TDataSet } CDS.Params.AssignValues(SavedParams); end; procedure TForm1.FormCreate(Sender: TObject); begin { Initialize SavedParams } SavedParams := TParams.Create; end; procedure TForm1.FormDestroy(Sender: TObject); begin SavedParams.Free; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|