Board index » delphi » Is ADO's bof/eof always reliable?

Is ADO's bof/eof always reliable?

I am using D5, MS Sql7 and ADO ...
Several times I have looped thru a TADOquery from first to last using 'Next'
and checked for the eof as per the following and it loops endlessly.

Is ADO's bof/eof always reliable?  If not, what else can I use?  If yes, why
might this happen?

with MyQuery do
begin
  first;
  while not eof do
  begin
    {process stuff}
     next;
  end;
end;

 

Re:Is ADO's bof/eof always reliable?


I've never had a problem. The{*word*128}thing that comes to mind is to make sure
that {process stuff} does not insert records, or edit them in some way that
would change their ordering. Also, make sure that Next is *always* called -
that's the one I usually fall for.

Marcelo Lopez Ruiz

Quote
"Sydney Lotterby" <t...@infosearch.com> wrote in message

news:3b290ad7$2_2@dnews...
Quote
> I am using D5, MS Sql7 and ADO ...
> Several times I have looped thru a TADOquery from first to last using
'Next'
> and checked for the eof as per the following and it loops endlessly.

> Is ADO's bof/eof always reliable?  If not, what else can I use?  If yes,
why
> might this happen?

> with MyQuery do
> begin
>   first;
>   while not eof do
>   begin
>     {process stuff}
>      next;
>   end;
> end;

Re:Is ADO's bof/eof always reliable?


I agree with your comments but (in the actual example below that uses
'prior') you can see that nothing else happens to the recs or table.  If
quTags only has 1 rec, in order to get this to work I have to use the dec(n)
approach.  Maybe I'm missing something obvious.  Here's the example.

  with quTags do
  begin
    DisableControls;
    last;
    n := RecordCount;
    repeat
      prior;    //Invokes "AfterScroll" event to build all fields if needed.
      dec(n);
//    until bof;          //Doesn't work! so use a counter
    until n=0;
    EnableControls;
  end;

"Marcelo Lopez Ruiz" <marcelo.lopezr...@xlnet.com.ar> wrote in message
news:3b2917b6_2@dnews...

Quote
> I've never had a problem. The{*word*128}thing that comes to mind is to make
sure
> that {process stuff} does not insert records, or edit them in some way
that
> would change their ordering. Also, make sure that Next is *always*
called -
> that's the one I usually fall for.

> Marcelo Lopez Ruiz

> "Sydney Lotterby" <t...@infosearch.com> wrote in message
> news:3b290ad7$2_2@dnews...
> > I am using D5, MS Sql7 and ADO ...
> > Several times I have looped thru a TADOquery from first to last using
> 'Next'
> > and checked for the eof as per the following and it loops endlessly.

> > Is ADO's bof/eof always reliable?  If not, what else can I use?  If yes,
> why
> > might this happen?

> > with MyQuery do
> > begin
> >   first;
> >   while not eof do
> >   begin
> >     {process stuff}
> >      next;
> >   end;
> > end;

Re:Is ADO's bof/eof always reliable?


Quote
"Sydney Lotterby" <t...@infosearch.com> wrote in message

news:3b2924a8$2_2@dnews...

Quote
> I agree with your comments but (in the actual example below that uses
> 'prior') you can see that nothing else happens to the recs or table.  If
> quTags only has 1 rec, in order to get this to work I have to use the
dec(n)
> approach.  Maybe I'm missing something obvious.  Here's the example.

>   with quTags do
>   begin
>     DisableControls;
>     last;
>     n := RecordCount;
>     repeat
>       prior;    //Invokes "AfterScroll" event to build all fields if
needed.
>       dec(n);
> //    until bof;          //Doesn't work! so use a counter
>     until n=0;
>     EnableControls;
>   end;

Syndney,

Firstly this code is not safe - you are assuming that there is at least one
record in quTags. Secondly 'last' takes you to the last record - this is not
at EOF just as BOF is not the first record. BOF is set when there are no
records or you try to scroll before the first record. EOF is set when there
are no records or you try to scroll past the last record.

This should work:

 with quTags do
 begin
    DisableControls;
    try
      Last;
      while not BOF do
      begin
        // do something with current record
        prior;
      end;
    finally
      EnableControls;
    end;
end;

Regards
Ian

Re:Is ADO's bof/eof always reliable?


Quote
"Ian Stuart" <ian.stu...@chello.at> wrote in message

news:3b299891$1_1@dnews...

 Syndney,

Apologises for the extra 'n' in your name...

Ian

Re:Is ADO's bof/eof always reliable?


Ian,
Thanks - you're right, it is faulty logic and the "while" needs to be used
not repeat to handle zero result sets.  But ... it still doesn't work for
me!  Here's the reason - the "AfterScroll" event triggered on this query
does a bunch of stuff and finally does a Post on the current record.  Looks
like this is what is preventing a BOF/EOF from happening.  I tried the loop
with Next and with Prior and got the same result.  How would you handle this
situation?

Quote
"Ian Stuart" <ian.stu...@chello.at> wrote in message

news:3b299891$1_1@dnews...
Quote
> "Sydney Lotterby" <t...@infosearch.com> wrote in message
> news:3b2924a8$2_2@dnews...
> > I agree with your comments but (in the actual example below that uses
> > 'prior') you can see that nothing else happens to the recs or table.  If
> > quTags only has 1 rec, in order to get this to work I have to use the
> dec(n)
> > approach.  Maybe I'm missing something obvious.  Here's the example.

> >   with quTags do
> >   begin
> >     DisableControls;
> >     last;
> >     n := RecordCount;
> >     repeat
> >       prior;    //Invokes "AfterScroll" event to build all fields if
> needed.
> >       dec(n);
> > //    until bof;          //Doesn't work! so use a counter
> >     until n=0;
> >     EnableControls;
> >   end;

> Syndney,

> Firstly this code is not safe - you are assuming that there is at least
one
> record in quTags. Secondly 'last' takes you to the last record - this is
not
> at EOF just as BOF is not the first record. BOF is set when there are no
> records or you try to scroll before the first record. EOF is set when
there
> are no records or you try to scroll past the last record.

> This should work:

>  with quTags do
>  begin
>     DisableControls;
>     try
>       Last;
>       while not BOF do
>       begin
>         // do something with current record
>         prior;
>       end;
>     finally
>       EnableControls;
>     end;
> end;

> Regards
> Ian

Other Threads