if Key=#13 then
begin
i:=0;
while i<SGrd.RowCount-2 do
begin
SGrd.Cells[2,i+1]:=Trim(Edit3.Text);
Edit3.Text:='';
Break;
end;
end;
i:=i+1;
Edit3.SetFocus;
begin
i:=0;
while i<SGrd.RowCount-2 do
begin
SGrd.Cells[2,i+1]:=Trim(Edit3.Text);
Edit3.Text:='';
Break;
end;
end;
i:=i+1;
Edit3.SetFocus;
如果你后面代码没有用到i的话!你i+1这句话就没什么意义啦!
delphi编译器还是挺聪明的啊!
即是i没有初始化,这时系统会给i一个初值,可能很大所以i要初始化,把i:=0放在第一句吧
i:=0;
//开始 while i<SGrd.RowCount-2 do
begin
SGrd.Cells[2,i+1]:=Trim(Edit3.Text);
Edit3.Text:='';
Break;//而且强行退出循环break没有这么用的,一般是在if ... then break;
//i:=i+1应在这或之前
//结束 end;
还有你没有判断 SGrd.RowCount-2 是否在范围之内,会出错的。
begin
i:=0;
while i<SGrd.RowCount-2 do
begin
SGrd.Cells[2,i+1]:=Trim(Edit3.Text);
Edit3.Text:='';
Break;
end;
end;
上去就break你还while干什么?
i :=i+1;后面如果用不到i的值就会被优化掉了。
begin
i := 0;
while i < SGrd.RowCount - 2 do
begin
SGrd.Cells[2, i + 1] := Trim(Edit3.Text);
Edit3.Text := '';
Break;
end;
end;
i := i + 1;
Edit3.SetFocus;
showmessage('i='+inttostr(i));
跟踪测试一下吧
if Key = #13 then
begin
i := 0;
while i < SGrd.RowCount - 2 do
begin
SGrd.Cells[2, i + 1] := Trim(Edit3.Text);
Edit3.Text := '';
Break;
end;
end;
i := i + 1;
showmessage('i='+inttostr(i));
Edit3.SetFocus;显示出来看一下就知道了哈
begin
i := 0;
while i < SGrd.RowCount - 2 do
begin
SGrd.Cells[2, i + 1] := Trim(Edit3.Text);
Edit3.Text := '';
i := i + 1;
Break;
end;
end;
Edit3.SetFocus;LZ 是不是想实现这样的功能,而写错代码了
begin
i:=0;
while i<SGrd.RowCount-2 do
begin
SGrd.Cells[2,i+1]:=Trim(Edit3.Text);
Edit3.Text:='';
//Break; 这行不要。
i:=i+1;//加在这里才会执行
end;
end;
Edit3.SetFocus;