功能----给每个记录加个序号,代码如下:
   total:=1;
   delQuery.Close;
   DelQuery.SQL.Clear;
   DelQuery.SQL.Add('select * from ylf');
   DelQuery.Open;
   while not delQuery.Eof do begin
      delQuery.Edit;
      delQuery.FieldByName('bz3').AsString :=IntToStr(total);
      total:=total+1;
      delquery.Next;
      end;
请问为什么上面的语句进入了死循环?
我该如何给每个记录加个序号?

解决方案 »

  1.   

    运行时提示:"stack overflow", 调试显示进入死循环,帮我呀!
      

  2.   

    试试看,也就是换种循环语句   
       total:=1;
       delQuery.Close;
       DelQuery.SQL.Clear;
       DelQuery.SQL.Add('select * from ylf');
       DelQuery.Open;
       delQuery.Edit;
       DelQuery.first;  //ADD
       for I;=0 to DelQuery.datebase...Count-1 do  //DelQuery.datebase...Count为记录数
       begin      
          delQuery.FieldByName('bz3').AsString :=IntToStr(total);
          total:=total+1;
          delquery.Next;
       end;
      

  3.   

    while not delQuery.Eof do begin  //这样当然是死循环了,你这个的意思是,如果不是
    //最后一条那就一直运行下去。你说能不死循环吗?
          delQuery.Edit;
          delQuery.FieldByName('bz3').AsString :=IntToStr(total);
          total:=total+1;
          delquery.Next;
          end;
      

  4.   

    数据库用的时Delphi6自己带的paradox,会不会是paradox有bug呢?
      

  5.   

    没用过paradox  不过应该不会有这种bug 吧,
    如果是死循环,单步调试的时候应能一直进行下去, 运行应该也不会提示呀 可能是某些方面有问题,不一定是死循环
      

  6.   

    DelQuery.DisableControls; 
       total:=1;
       delQuery.Close;
       DelQuery.SQL.Clear;
       DelQuery.SQL.Add('select * from ylf');
       DelQuery.Open;
       while not delQuery.Eof do begin
          delQuery.Edit;
          delQuery.FieldByName('bz3').AsString :=IntToStr(total);
          total:=total+1;
          delquery.Next;
          end;
        DelQuery.EnableControls; 
      

  7.   

    表中有BLOB字段吗?如果有的话,别用select *,只select你要用的字段。
      

  8.   

    你用showmessage('问题提示!');调试一下!
      

  9.   

    用SQL数据库试了一下,没问题。
    其它哪里有问题吧
      

  10.   

    给你写个:
    with DelQuery do
    begin
      close;
      sql.clear;
      sql.add('select * from ylf');
      open;
      while not Eof do
      begin
       edit;
       fieldbyname('bz3').AsString := InttoStr(RecNo);
       Next;
      end;
    end;
      

  11.   

    我敢说Paradox5肯定是有问题的,select * from ylf 和select * from ylf order by bz3
    返回的结果竟然不一样,不是我亲自碰见我简直不敢相信!!!
      

  12.   

    代码本身没有问题,PARADOX也没有问题(非常稳定),请检查是否与别的数据表关联?
      

  13.   

    DelQuery.first;
    你怎么把它丢了
      

  14.   

    嗯 !这里对记录的修改都没有提交给数据库,加这个:delQuery.Post
      

  15.   

    怎么不信我说的?大家说说“stack overflow”除了在递归没有出口的情况之外哪里还可以遇到?把全部的代码贴出了,包括函数名称和如何调用的。