RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TParams.AssignValues Method

Assigns new values to the parameters of the Items property.

Pascal
procedure AssignValues(Value: TParams);
C++
__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.  

Delphi Examples: 

 

var SavedParams: TParams;
{ Initialize SavedParams }
SavedParams := TParams.Create;
try
  { Save the parameters for SQLDataSet1 }
  SavedParams.Assign(SQLDataSet1.Params);
  { Do something with SQLDataSet1 }
  ...
  { Restore the parameters to SQLDataSet1 }
  SQLDataSet1.Params.AssignValues(SavedParams);
finally
  SavedParams.Free;
end; 

 

{
  This example saves params from a ClientDataSet, alters them
  and restores them.
}
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) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!