为了以某种顺序显示我的数据,我有order列。这样我就可以上下移动行。这已经起作用了,我只是把订单号换成受影响的行。我的问题是,当我删除一行时,我需要重新排序所有其他行。为了按照正确的顺序显示行,我使用.IndexFieldNames := ' order ',但是当我遍历所有行并分配新的序号时,它的活动索引非常慢。当我移除.IndexFieldNames := '‘时,行不再按正确的顺序排列,而新的顺序是错误的。
这是我的代码:
class procedure TDataModuleEx.ReOrderColumn(const aDataSet: TClientDataSet;
const aFieldName: string; aResetClone: Boolean);
var
clone: TClientDataSet;
newOrderNo: Integer;
begin
newOrderNo := 0;
clone := TClientDataSet.Create(nil);
try
clone.CloneCursor(aDataSet, aResetClone);
clone.IndexFieldNames := aFieldName;
clone.IndexFieldNames := ''; //Indexed Edit is too slow
clone.First;
while not clone.eof do
begin
Inc(newOrderNo);
clone.Edit;
clone.FieldByName(aFieldName).AsInteger := newOrderNo;
clone.Post;
clone.Next;
end;
finally
clone.Free;
end;
end;如何在有效删除行后重新排序?
发布于 2015-06-10 11:41:25
我在一张有10000张记录的桌子上做了一些测试。过程ReOrderColumn使重命名了大约3秒。ClientDataSet。ApplyUpdate花了大约30秒。
总计约33秒。
我在Firebird数据库中编写了存储过程,使得为重命名大约3秒。
SET TERM ^ ;
create or alter procedure REORDER
as
declare variable ID integer;
declare variable I integer;
BEGIN
i = 0;
FOR
select new_table.id
from new_table
order by FORDER
INTO :ID
as cursor tcur
DO
BEGIN
i = :i + 1;
update new_table t set t.forder = :i
where current of tcur;
END
END^
SET TERM ; ^来自德尔菲
procedure Reorder;
begin
//Apply changes to server
dm1.ClientDataSet1.ApplyUpdates(0);
//execute stored procedure
dm1.spReorder.ExecProc; <--- ABOUT 3 SEC FOR 10 000 records
//Refresh dataset
dm1.ClientDataSet1.Close;
dm1.ClientDataSet1.Open;
end;https://stackoverflow.com/questions/30750342
复制相似问题