我如何让adoquery循环?我加上first,while not eof do 就出错了var
I: Integer;
begin
for I := 1 to 6 do
with TEasyGrid(FindComponent(Format('EasyGrid%d', [I]))),
TADOQuery(FindComponent(Format('ADOQuery%d', [I]))) do
begin
first//////
while not eof do ///////
Cells[
FieldByName('colnum').AsInteger,
FieldByName('rownum').AsInteger].ForeText := FieldByName('mc').AsString;
end;/////////
end;
I: Integer;
begin
for I := 1 to 6 do
with TEasyGrid(FindComponent(Format('EasyGrid%d', [I]))),
TADOQuery(FindComponent(Format('ADOQuery%d', [I]))) do
begin
first//////
while not eof do ///////
Cells[
FieldByName('colnum').AsInteger,
FieldByName('rownum').AsInteger].ForeText := FieldByName('mc').AsString;
end;/////////
end;
first//////
while not eof do ///////
begin
Cells[
FieldByName('colnum').AsInteger,
FieldByName('rownum').AsInteger].ForeText := FieldByName('mc').AsString;
next;
end;
end;/////////
///first后面没有冒号
///在while not eof循环中没有next语句来移动记录不好意思,是我提问时漏了,
问题不在标点和next上,我的程序里有的。
编译可以通过,程序执行的时候提示“存取地址为例“
如果我把循环去掉就可以执行,但是这样就只能现实第一条记录了,这可不行啊!
FieldByName('rownum').AsInteger
因为程序执行到first就错了,光标定位到这,说程序存取地址违例
如果我把first换城adoquery1.first或者adoquery2.first,,,,adoquery6.first她都不错
with TEasyGrid(FindComponent(Format('EasyGrid%d', [i]))) do
if i=1 then
with adoquery1 do
begin
open;
first;
while not eof do
begin
Cells[FieldByName('colnum').AsInteger, FieldByName('rownum').AsInteger].ForeText := FieldByName('mc').AsString;
next
end;
if i=2 then
with adoquery2 do
begin
open;
first;
while not eof do
begin
Cells[FieldByName('colnum').AsInteger, FieldByName('rownum').AsInteger].ForeText := FieldByName('mc').AsString;
next
end;
这是我用最笨的方法作的,他就可以执行
for i:=1 to 6 do
with TEasyGrid(FindComponent(Format('EasyGrid%d', [i]))),
TADOQuery(FindComponent(Format('ADOQuery%d', [i]))) do
begin
open;
first;//////
while not eof do ///////
begin
Cells[FieldByName'colnum').AsInteger,FieldByName'rownum').AsInteger].ForeText := FieldByName('mc').AsString;
next;
end;
end;/////////
var
I: Integer;
vADOQuery: TADOQuery;
vEasyGrid: TEasyGrid;
begin
for I := 1 to 6 do
begin
TComponent(vADOQuery) := FindComponent(Format('ADOQuery%d', [I]));
TComponent(vEasyGrid) := FindComponent(Format('EasyGrid%d', [I]));
vADOQuery.Open;
vADOQuery.First;
while not vADOQuery.Eof do
begin
vEasyGrid.Cells[
vADOQuery.FieldByName('colnum').AsInteger,
vADOQuery.FieldByName('rownum').AsInteger
].ForeText := vADOQuery.FieldByName('mc').AsString;
vADOQuery.Next;
end;
vADOQuery.Close;
end;
end;
相当于
with A do
with B dowith TEasyGrid(FindComponent(Format('EasyGrid%d', [I]))), TADOQuery(FindComponent(Format('ADOQuery%d', [I]))) do
就被解释成
with TEasyGrid(FindComponent(Format('EasyGrid%d', [I]))) do
with TADOQuery(TEasyGrid(FindComponent(Format('EasyGrid%d', [I]))).FindComponent(Format('ADOQuery%d', [I]))) do
因为FindComponent是TComponent的方法~~
EasyGridX.FindComponent就找不到什么了~~
TADOQuery(nil).Open;当然就会出错!~~var
I: Integer;
begin
for I := 1 to 6 do
with TEasyGrid(FindComponent(Format('EasyGrid%d', [I]))),
TADOQuery(Self.FindComponent(Format('ADOQuery%d', [I]))) do
begin
Open;
First;
while not Eof do
begin
Cells[
FieldByName'colnum').AsInteger,
FieldByName'rownum').AsInteger
].ForeText := FieldByName('mc').AsString;
Next;
end;
Close;
end;
end;
哥们,佩服你,也麻烦你了,一切都搞定了,
谢谢,谢谢了。