TFDQuery and TADOQuery with identical syntax

76 Views Asked by At

I want to extend the class TMyQuery with the property parameters. I want to call TMyQuery with the same syntax as using a TADOQuery. How to extend my Class correctly ?

///  new class    
type TMyQuery = class (TFDQuery)
      private
    
        procedure SetParamByName(const Param: TParam);
       public
       ///  here i fail ! 
       property Parameters[const AName: string]: TParam  Write SetParamByName;
    end;
    
procedure TMyQuery.SetParamByName(const Param: TParam);
begin
   // Params.ParamByName(AName). ???  ;
end;    
///  code example    
...
...
///  calling FFDQuery with same syntax like ADO Query     
qryInsert.Parameters.ParamByName('ID').AsInteger := recordCount;
1

There are 1 best solutions below

2
Germán Estévez -Neftalí- On

You can try some like this:

  TMyQuery = class (TFDQuery)
  private
    procedure SetParamByName(const AName: string; const Value: TParam);
  public
    /// ...
    property Parameters[const AName: string]: TParam  Write SetParamByName;
  end;

On implementation of the procedure try this:

procedure TMyQuery.SetParamByName(const AName: string; const Value: TParam);
begin
  inherited ParamByName(AName).Value := Value.Value;
end;

Is this what you need?