procedure delAllRow();
var
i,rCount:integer;
begin
rCount:= Form1.valueListEdit1.rCount;
for i:=1 to rCount do
begin
Form1.valueListEdit1.DeleteRow(i);
end;
end;我在watch窗口中,观察 i 和 rCount 变量,居然发现,每一次循环,i是自增的,但是rCount却在自减,不知这是delphi的bug还是CPU的BUG
按理来说,Form1.valueListEdit1.rCount会自减是正常的,因为delete了一行,他的行数就减一,但是rCount却应该是不变的。程序作用就是把valuleListEdit1
中的各行删除,有人愿意把代码COPY到DELPHI中,帮我验证一下是否CPU的错误吗?
var
i,rCount:integer;
begin
rCount:= Form1.valueListEdit1.rCount;
for i:=1 to rCount do
begin
Form1.valueListEdit1.DeleteRow(i);
end;
end;我在watch窗口中,观察 i 和 rCount 变量,居然发现,每一次循环,i是自增的,但是rCount却在自减,不知这是delphi的bug还是CPU的BUG
按理来说,Form1.valueListEdit1.rCount会自减是正常的,因为delete了一行,他的行数就减一,但是rCount却应该是不变的。程序作用就是把valuleListEdit1
中的各行删除,有人愿意把代码COPY到DELPHI中,帮我验证一下是否CPU的错误吗?
begin
Form1.valueListEdit1.DeleteRow(1);
rCount:=rCount-1;
end;或者,用for语句就用downto
for i:=rCount downto 1 do
begin
Form1.valueListEdit1.DeleteRow(i);
end;
var
i,rCount:integer;
begin
rCount:= Form1.valueListEdit1.rCount;
for i:=1 to rCount do
begin
Form1.valueListEdit1.DeleteRow(i);
end;
end;楼主,你的代码有问题。
在你删除第一行后,原第二行就成了新第一行,原第三行成了新第二行,以此类推。
而你的代码却是在删除第一行后,删除第二行,注意,此时的第二行已经是原来的第三行了。你可以采用do2008(事情做了,才是事情)的方法。
建议用他的第二个写法。第一个写法有目标代码冗余,会多消耗CPU指令时间。
begin
for i:=rCount downto 1 do
DeleteRow(i);
end;
~~----------------------
当然了~~你是删了它的数据 rCount当然要减了~~