Z
zyycc
Unregistered / Unconfirmed
GUEST, unregistred user!
我定义了一个类,其内部包含了几个字符串及嵌套了包含字符串的对象,
然后,再将其放如ADOQuery中published,但在属性编辑中编辑后,关闭项目
再打开,发现刚才的修改并未保存,请大家帮帮忙。
代码如下
---ifc.pas------
unit Ifc;
interface
uses Classes;
type
TSQLFields = class(TPersistent)
private
FOriFields: TStrings;
FOutFields: TStrings;
procedure SetOriFields(const value:TStrings);
procedure SetOutFields(const value:TStrings);
public
constructor Create; //override;
destructor Destroy; override;
published
property OriFields:TStrings read FOriFields write SetOriFields;
property OutFields:TStrings read FOutFields write SetOutFields;
end;
TSQLstm = class(TPersistent)
private
FOriSQL: TStrings;
FWhere: TStrings;
FOrder: TStrings;
FSQLFields: TSQLFields;
FVersion:TStrings;
procedure SetOriSQL(const value:TStrings);
procedure SetWhere(const value:TStrings);
procedure SetOrder(const value:TStrings);
public
constructor Create; //override;
destructor Destroy; override;
published
property OriSQL:TStrings read FOriSQL write SetOriSQL;
property Where: TStrings read FWhere write SetWhere;
property Order: TStrings read FOrder write SetOrder;
property SQLFields: TSQLFields read FSQLFields;
end;
implementation
{ TSQLFields }
constructor TSQLFields.Create;
begin
inherited;// Create;
FOriFields := TStringList.Create;
FOutFields := TStringList.Create;
end;
destructor TSQLFields.Destroy;
begin
FOriFields.Destroy;
FOutFields.Destroy;
inherited;
end;
procedure TSQLFields.SetOriFields(const value: TStrings);
begin
FOriFields.Add(value.Text);
end;
procedure TSQLFields.SetOutFields(const value: TStrings);
begin
FOutFields.AddStrings(value);
end;
{ TSQLstm }
constructor TSQLstm.Create;
begin
inherited;// Create;
FOriSQL:=TStringList.Create;
FWhere:=TStringList.Create;
FOrder:=TStringList.Create;
FSQLFields:=TSQLFields.Create;
end;
destructor TSQLstm.Destroy;
begin
FOriSQL.Destroy;
FWhere.Destroy;
FOrder.Destroy;
FVersion.Destroy;
FFilter.Destroy;
FSQLFields.Destroy;
inherited;
end;
procedure TSQLstm.SetOrder(const value: TStrings);
begin
FOrder.AddStrings(value);
end;
procedure TSQLstm.SetOriSQL(const value: TStrings);
begin
FOriSQL.AddStrings(value);
end;
procedure TSQLstm.SetWhere(const value: TStrings);
begin
FWhere.AddStrings(value);
end;
end.
---ZyADOQry.pas---
unit zyADOQry;
interface
uses Ifc,SysUtils,DB, ADODB,Classes;
type
TzyADOQry = class(TADOQuery)
private
FSQLstm: TSQLstm;
function GetCmpValue:Boolean;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Changed:Boolean read GetCmpValue default false;
property SQLstm:TSQLstm read FSQLstm;
end;
//TSQLstmProperty = class(TPropertyEditor)
// function GetAttributes:TPropertyAttributes; override;
// function GetValue:string; override;
// end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('ZyCtrls', [TzyADOQry]);
end;
{ TzyADOQry }
function TzyADOQry.GetCmpValue;
var i:integer;
begin
Result:=False;
if Self.Active=True then
begin
for i:=0 to Self.FieldCount-1 do
begin
if not (TrimRight(string(Self.Fields.Value)) = TrimRight(string(Self.Fields.OldValue))) then
begin
Result:=True;
break;
end;
end;
end;
end;
constructor TzyADOQry.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FSQLstm := TSQLstm.Create;
end;
destructor TzyADOQry.Destroy;
begin
FSQLstm.Destroy;
inherited;
end;
end.
然后,再将其放如ADOQuery中published,但在属性编辑中编辑后,关闭项目
再打开,发现刚才的修改并未保存,请大家帮帮忙。
代码如下
---ifc.pas------
unit Ifc;
interface
uses Classes;
type
TSQLFields = class(TPersistent)
private
FOriFields: TStrings;
FOutFields: TStrings;
procedure SetOriFields(const value:TStrings);
procedure SetOutFields(const value:TStrings);
public
constructor Create; //override;
destructor Destroy; override;
published
property OriFields:TStrings read FOriFields write SetOriFields;
property OutFields:TStrings read FOutFields write SetOutFields;
end;
TSQLstm = class(TPersistent)
private
FOriSQL: TStrings;
FWhere: TStrings;
FOrder: TStrings;
FSQLFields: TSQLFields;
FVersion:TStrings;
procedure SetOriSQL(const value:TStrings);
procedure SetWhere(const value:TStrings);
procedure SetOrder(const value:TStrings);
public
constructor Create; //override;
destructor Destroy; override;
published
property OriSQL:TStrings read FOriSQL write SetOriSQL;
property Where: TStrings read FWhere write SetWhere;
property Order: TStrings read FOrder write SetOrder;
property SQLFields: TSQLFields read FSQLFields;
end;
implementation
{ TSQLFields }
constructor TSQLFields.Create;
begin
inherited;// Create;
FOriFields := TStringList.Create;
FOutFields := TStringList.Create;
end;
destructor TSQLFields.Destroy;
begin
FOriFields.Destroy;
FOutFields.Destroy;
inherited;
end;
procedure TSQLFields.SetOriFields(const value: TStrings);
begin
FOriFields.Add(value.Text);
end;
procedure TSQLFields.SetOutFields(const value: TStrings);
begin
FOutFields.AddStrings(value);
end;
{ TSQLstm }
constructor TSQLstm.Create;
begin
inherited;// Create;
FOriSQL:=TStringList.Create;
FWhere:=TStringList.Create;
FOrder:=TStringList.Create;
FSQLFields:=TSQLFields.Create;
end;
destructor TSQLstm.Destroy;
begin
FOriSQL.Destroy;
FWhere.Destroy;
FOrder.Destroy;
FVersion.Destroy;
FFilter.Destroy;
FSQLFields.Destroy;
inherited;
end;
procedure TSQLstm.SetOrder(const value: TStrings);
begin
FOrder.AddStrings(value);
end;
procedure TSQLstm.SetOriSQL(const value: TStrings);
begin
FOriSQL.AddStrings(value);
end;
procedure TSQLstm.SetWhere(const value: TStrings);
begin
FWhere.AddStrings(value);
end;
end.
---ZyADOQry.pas---
unit zyADOQry;
interface
uses Ifc,SysUtils,DB, ADODB,Classes;
type
TzyADOQry = class(TADOQuery)
private
FSQLstm: TSQLstm;
function GetCmpValue:Boolean;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Changed:Boolean read GetCmpValue default false;
property SQLstm:TSQLstm read FSQLstm;
end;
//TSQLstmProperty = class(TPropertyEditor)
// function GetAttributes:TPropertyAttributes; override;
// function GetValue:string; override;
// end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('ZyCtrls', [TzyADOQry]);
end;
{ TzyADOQry }
function TzyADOQry.GetCmpValue;
var i:integer;
begin
Result:=False;
if Self.Active=True then
begin
for i:=0 to Self.FieldCount-1 do
begin
if not (TrimRight(string(Self.Fields.Value)) = TrimRight(string(Self.Fields.OldValue))) then
begin
Result:=True;
break;
end;
end;
end;
end;
constructor TzyADOQry.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FSQLstm := TSQLstm.Create;
end;
destructor TzyADOQry.Destroy;
begin
FSQLstm.Destroy;
inherited;
end;
end.