我如何让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;

解决方案 »

  1.   

    first后面没有冒号在while not eof循环中没有next语句来移动记录
      

  2.   

    begin
       first//////
    while not eof do ///////
    begin 
         Cells[
            FieldByName('colnum').AsInteger,
            FieldByName('rownum').AsInteger].ForeText := FieldByName('mc').AsString;
         next;
    end;
    end;/////////
      

  3.   

    hnhb(不死鸟), juliens(星星球) ( 
    ///first后面没有冒号
    ///在while not eof循环中没有next语句来移动记录不好意思,是我提问时漏了,
    问题不在标点和next上,我的程序里有的。
    编译可以通过,程序执行的时候提示“存取地址为例“
    如果我把循环去掉就可以执行,但是这样就只能现实第一条记录了,这可不行啊!
      

  4.   

    你自己检查下,这些值是否越界~~FieldByName('colnum').AsInteger
    FieldByName('rownum').AsInteger
      

  5.   

    那先判断这个记录集中是否有数据,如果没有数据就不要first了,也不要循环了
      

  6.   

    应该不是FieldByName('colnum').AsInteger,FieldByName('rownum').AsInteger越界
    因为程序执行到first就错了,光标定位到这,说程序存取地址违例
    如果我把first换城adoquery1.first或者adoquery2.first,,,,adoquery6.first她都不错
      

  7.   

    參考 hnhb(不死鸟)  的意見!然後, 你的 with 我感覺用得不是很好, 可能會混淆
      

  8.   

    for i := 1 to 6 do
        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;
    这是我用最笨的方法作的,他就可以执行
      

  9.   

    这是循环的代码,光标定位到open;出错
    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;/////////
      

  10.   

    //改成这样~~
    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;
      

  11.   

    问题明白了~~with A, B do
    相当于
    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;
      

  12.   

    zswangII(伴水清清)(一贴不灌,何以灌天下?) 
    哥们,佩服你,也麻烦你了,一切都搞定了,
    谢谢,谢谢了。