TEdit和TQuery

时间:2015-01-13 12:53:47

标签: class delphi properties interface tquery

我上课了:

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

通过这种方式,我将TQuery作为属性,我可以更改属性查询。我需要其他东西,改变tQuery的属性并将它们保存在dfm中。我不希望TQuery在表单上可见。实际上我使用TFDQuery。我怎样才能做到这一点?

2 个答案:

答案 0 :(得分:3)

不要将您的fQuery公开为TcvDbEdit的公共成员,而是公开您需要的属性 -

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;

答案 1 :(得分:1)

也许您需要SetSubComponent。