肯定是死循环啦,你看看:
var i:integer;
begin
with qry_column do
begin
close;
open;
first;
while not eof do
ShowMessage(IntToStr(qry_column.recordcount));
for i:=0 to qry_column.recordcount-1 do
begin
if dbgrid1.columns[i].fieldname=fieldbyname('zdm').asstring then
if fieldbyname('xzzt').integer=1 then
dbgrid1.columns[i].visible:= true
else
dbgrid1.columns[i].visible:= false; end;
i:=i+1; //你看看,这条语句在循环之外,
next; //这条位置也错了!
end;
close;
end;
修改后如下所示:
var i:integer;
begin
with qry_column do
begin
close;
open;
first;
while not eof do
ShowMessage(IntToStr(qry_column.recordcount));
for i:=0 to qry_column.recordcount-1 do
begin
if dbgrid1.columns[i].fieldname=fieldbyname('zdm').asstring then
if fieldbyname('xzzt').integer=1 then
dbgrid1.columns[i].visible:= true
else
dbgrid1.columns[i].visible:= false;
i:=i+1;
next;
end;
end;
close;
end;
var i:integer;
begin
with qry_column do
begin
close;
open;
first;
while not eof do
ShowMessage(IntToStr(qry_column.recordcount));
for i:=0 to qry_column.recordcount-1 do
begin
if dbgrid1.columns[i].fieldname=fieldbyname('zdm').asstring then
if fieldbyname('xzzt').integer=1 then
dbgrid1.columns[i].visible:= true
else
dbgrid1.columns[i].visible:= false; end;
i:=i+1; //你看看,这条语句在循环之外,
next; //这条位置也错了!
end;
close;
end;
修改后如下所示:
var i:integer;
begin
with qry_column do
begin
close;
open;
first;
while not eof do
ShowMessage(IntToStr(qry_column.recordcount));
for i:=0 to qry_column.recordcount-1 do
begin
if dbgrid1.columns[i].fieldname=fieldbyname('zdm').asstring then
if fieldbyname('xzzt').integer=1 then
dbgrid1.columns[i].visible:= true
else
dbgrid1.columns[i].visible:= false;
i:=i+1;
next;
end;
end;
close;
end;
应该是:
var i:integer;
begin
with qry_column do
begin
close;
open;
first;
while not eof do
begin //加上
ShowMessage(IntToStr(qry_column.recordcount));
for i:=0 to qry_column.recordcount-1 do
begin
if dbgrid1.columns[i].fieldname=fieldbyname('zdm').asstring then
if fieldbyname('xzzt').integer=1 then
dbgrid1.columns[i].visible:= true
else
dbgrid1.columns[i].visible:= false;
//i:=i+1; //这是循环变量,不能 赋值,若有其他用途请换名
end;
next; //放在for 循环的外面,while 循环里面
end; //while 结束
close;
end;
end;你刚才的next 没有放在while 循环里面,当然死循环