S
SUNSTONE的Delphi笔记
Unregistered / Unconfirmed
GUEST, unregistred user!
调用FieldByName主要是调用FindField,会在主循环引进n个新子循环,如果有1万个记录,那效率会可想而知。
下面优化比较好
var
AField : TField;
begin
Assert(AdoQuery1.Active, 'Dataset is not active!');
try
AdoQuery1.DisableControls;
AField := AdoQuery1.FieldByName('MyFieldName');
AdoQuery1.First;
while not AdoQuery1.Eof do
begin
AdoQuery1.Edit;
AField.Value := Edit1.Text;
AdoQuery1.Post;
AdoQuery1.Next;
end;
finally
AdoQuery1.EnableControls;
end;
end;
如果有多个字段,想简化一下
const ROWCOUNT = 1000000;
var
k, j: Integer;
FieldList: iFieldList;
begin
FieldList := GetFieldList(ClientDataSet1);
ClientDataSet1.Active := False;
ClientDataSet1.Active := True;
for j := 1 to ROWCOUNT do
begin
ClientDataSet1.Append;
for k := 1 to 10 do
FieldList.FieldByName('ClientDataSet1Field' + IntToStr(k)).AsInteger := k;
ClientDataSet1.Post;
end;
end;
作者:sunstone 发表于2011/1/23 8:13:00 原文链接
阅读:1656 评论:0 查看评论
查看更多...
下面优化比较好
var
AField : TField;
begin
Assert(AdoQuery1.Active, 'Dataset is not active!');
try
AdoQuery1.DisableControls;
AField := AdoQuery1.FieldByName('MyFieldName');
AdoQuery1.First;
while not AdoQuery1.Eof do
begin
AdoQuery1.Edit;
AField.Value := Edit1.Text;
AdoQuery1.Post;
AdoQuery1.Next;
end;
finally
AdoQuery1.EnableControls;
end;
end;
如果有多个字段,想简化一下
const ROWCOUNT = 1000000;
var
k, j: Integer;
FieldList: iFieldList;
begin
FieldList := GetFieldList(ClientDataSet1);
ClientDataSet1.Active := False;
ClientDataSet1.Active := True;
for j := 1 to ROWCOUNT do
begin
ClientDataSet1.Append;
for k := 1 to 10 do
FieldList.FieldByName('ClientDataSet1Field' + IntToStr(k)).AsInteger := k;
ClientDataSet1.Post;
end;
end;
作者:sunstone 发表于2011/1/23 8:13:00 原文链接
阅读:1656 评论:0 查看评论
查看更多...