【发布时间】:2010-01-20 04:06:24
【问题描述】:
有没有更快的方法?我基本上需要一次将 AA-ZZ 添加到数千条记录中。
仅包含 35 个项目的列表需要相当长的时间才能完成更不用说一千个列表。
procedure Tmainform.btnSeederClick(Sender: TObject);
var
ch,ch2:char;
i:integer;
slist1, slist2:TStrings;
begin
slist1:= TStringList.Create;
slist2:= TStringList.Create;
slist1.Text :=queuebox.Items.Text;
for ch := 'a' to 'z' do
begin
for ch2 := 'a' to 'z' do
begin
//
for I := 0 to slist1.Count - 1 do
begin
application.ProcessMessages; // so it doesn't freeze the application in long loops. Not 100% sure where this should be placed, if at all.
sleep(1); //Without this it doesn't process the cancel button.
if cancel then Break;
slist2.Add(slist1.Strings[i]+ch+ch2);
end;
end;
end;
insertsingle(slist2,queuebox);
freeandnil(slist1);
freeandnil(slist2);
结束;
感谢您的帮助
【问题讨论】:
-
你能举个例子吗?我不明白我怎么能只用一个循环来做到这一点。必须做AA,AB,AC ... ZZ
-
请从可以编译的示例代码开始。对,您的代码取决于“queuebox”、“cancel”和“insertsingle”,但它们不存在。我猜 queuebox 是一个列表框,但它是吗?
标签: delphi loops for-loop performance