【问题标题】:TEdit and TQueryTEdit 和 TQuery
【发布时间】:2015-03-11 10:36:08
【问题描述】:
我有课:
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。我怎样才能做到这一点?
【问题讨论】:
标签:
class
delphi
properties
interface
tquery
【解决方案1】:
不要将您的 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;