今天听说下面的这种写法
while not (qry.Eof and qry.Bof) do
beginend;
要比下面的这种写法严格,
while not qry.Eof do
beginend;可是我看不出严格在哪里,
哪位指点一下啊。

解决方案 »

  1.   

    第一条记录(First)之前就是Bof,最后一条记录(Last)之后就是Eof。
    如果是依次读取数据集中的记录,
    while not (qry.Eof and qry.Bof) do
    beginend;
    的用法是错误的。
    如果是判断qry中是否有记录可以使用
    if not (qry.Eof and qry.Bof) then  //表示qry数据集中有记录。如果是依次读取数据集中的记录:
    qry.First; 
    while not qry.Eof do
    begin
      s:=qry.fieldbyname('sss').asstring;
      qry.next;
    end;
    或者(从最后的记录往前读取):
    qry.last;
    while not qry.Bof do
    begin
      s:=qry.fieldbyname('sss').asstring;
      qry.Prior;
    end;
      

  2.   

    感觉楼主说的有一定道理,如果判断Query中有没有记录
    感觉似乎用
    while not (qry.Eof and qry.Bof) do
    beginend;
    是不是好一点呢
      

  3.   

    to  convertor(刘辉):
    为什依次读取数据集中的记录时
    while not (qry.Eof and qry.Bof) do
    beginend;
    的用法是错误的?我觉得
    while not (qry.Eof and qry.Bof) do

    while not qry.Eof do
    没有区别的啊。
      

  4.   

    while not (qry.Eof and qry.Bof) do
    beginend;
    依次读取数据集中的记录一定是错的。EOF指数据指针已经出了最后一条记录。BOF指数据指针已经出了第一条记录。你说这样还可以依次取得数据指针里的记录吗?
    只能是
    query1.first;
    while not query1.eof do
    begin
    ...
    query1.next;
    end;

    query1.last;
    while not query1.bof do 
    begin
    ...
    query.piror;
    end;
      

  5.   

    无非就是离散数学一开始讲的转换而已
    not (qry.Eof and qry.Bof)<=>(not qry.Eof) or (not qry.Bof)这样一看,这么写是有问题的如果你在开始的时候就使用了qry.first,那岂不是不循环了推荐的写法还是
    qry.First;
    while not qry.Eof do
    //
    qry.Next;