1

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?

kobik
  • 21,001
  • 4
  • 61
  • 121
user1969258
  • 99
  • 2
  • 7

2 Answers2

3

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;
kgu87
  • 2,050
  • 14
  • 12
1

Maybe you need of SetSubComponent.

Sanders the Softwarer
  • 2,478
  • 1
  • 13
  • 28