RAD Studio VCL Reference
|
Assigns new values to the parameters of the Items property.
procedure AssignValues(Value: TParams);
__fastcall AssignValues(TParams Value);
Use AssignValues to update the values of the field parameters in the Items list to match the values of the corresponding field parameters in another TParams object. For each entry in Items, the AssignValues method attempts to find a parameter with the same Name property in Value. If successful, the parameter information (type and current data) from the Value parameter is assigned to the Items entry. Entries in Items for which no match is found are left unchanged.
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!
|