看来还真是复杂了。
1、把下面这段代码拷贝进去
procedure CopyFields(S, D: TDataSet);
var
I: Integer;
F: TDataField;
begin
for I := 0 to D.FieldCount - 1 do
begin
F := S.FindField(D.Fields[I].FieldName);
if F <> nil then
D.Fields[I].Assign(F);
end;
end;
2、屏蔽15楼的代码,被下面的代码替换
var
S: string;
I: Integer;
Q: TSQLDataSet;
ATaskDataSet: TSQLDataSet;
SaveReadOnly, SaveFiltered: Boolean;
begin
ATaskDataSet := DataSetTaskIndex;
if not ATaskDataSet.Active then
Exit;
S := System.String.Join(''', ''', TaskGUID);
Q := TSQLDataSet.Create(ATaskDataSet.Owner);
try
Q.Database.URL := ATaskDataSet.Database.URL;
Q.SQL.Text := 'select * from TTASK where FGROUPGUID = ''-1'' AND FGUID in (''' + S + ''')';
Q.SQLFilter := ATaskDataSet.SQLFilter;
Q.SQLFiltered := ATaskDataSet.SQLFiltered;
Q.UserFilter := ATaskDataSet.UserFilter;
Q.Open;
Q.Order := 'FGUID';
ATaskDataSet.DisableControls;
SaveReadOnly := ATaskDataSet.ReadOnly;
SaveFiltered := ATaskDataSet.Filtered;
try
ATaskDataSet.ReadOnly := False;
ATaskDataSet.Filtered := False;
ATaskDataSet.First;
for I := Low(TaskGUID) to High(TaskGUID) do
begin
S := TaskGUID[I];
if ATaskDataSet.Locate('FGUID', [S], []) then
if Q.FindKey([S]) then
begin
ATaskDataSet.Edit;
try
CopyFields(Q, ATaskDataSet);
ATaskDataSet.Post;
except
ATaskDataSet.Cancel;
raise;
end;
end
else
ATaskDataSet.Delete
else
if Q.FindKey([S]) then
begin
ATaskDataSet.Append;
try
CopyFields(Q, ATaskDataSet);
ATaskDataSet.Post;
except
ATaskDataSet.Cancel;
raise;
end;
end;
end;
finally
ATaskDataSet.Filtered := SaveFiltered;
ATaskDataSet.ReadOnly := SaveReadOnly;
ATaskDataSet.EnableControls;
end;
finally
Q.Free;
end;
// TTaskServices.TaskUpdate(DataSetTaskIndex, TaskGUID);
end;
这样就可以了 |