TParamsAssign (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

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

Code

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;

Uses

Personal tools
Assistance