TEdit and TQuery

181 views Asked by At

I have class:

TcvDbedit = class(TCustomMaskEdit)
...
private
  ...
  fQuery: TQuery;
  ...
protected
  ...
public
  constructor Create(AOwner: TComponent); override;
  destructor Destroy; override;
  ...
published
  ...
  property DataQuery: TQuery read fQuery write fQuery;
  ...

in this way I get TQuery as a property and I can change property query. I need something else, to change properties of tQuery and to save them in dfm. I don't want TQuery to be visible on form. Actually I work with TFDQuery. How can I achieve that?

2

There are 2 answers

0
Sanders the Softwarer On BEST ANSWER

Maybe you need of SetSubComponent.

1
kgu87 On

Don't expose your fQuery as public member of TcvDbEdit, but rather expose properties you need -

interface

TcvDbedit = class(TCustomMaskEdit)
private
  fQuery: TQuery;
  procedure SetSQL(AValue : String);
  function GetSQL;
public
  constructor Create(AOwner: TComponent); override;
  destructor Destroy; override;
published
  property SQL : TStrings read GetSQL write SetSQL;
end;

implementation

constructor TcvDbedit.Create(AOwner : TComponent);
begin
  fQuery = TQuery.Create(self);
end

destructor TcvDbedit.Destroy;
begin
   fQuery.Free;
end;

procedure TcvDbedit.SetValue(AValue : String);
begin
  fQuery.SQL.Assign(AValue);
end;

function TcvDbedit.GetSQL : TStrings;
begin
  return fQuery.SQL;
end;