Subject Re: [IBO] EOF BOF craziness
Author Paul Vinkenoog
Hi Paul,

>> for ( MyDataset->First(); ! MyDataset->Eof; MyDataset->Next() )
>>
>> The day Jason decides to change First and Next like you propose,
>> these loops will still compile fine but they will become black
>> holes: what goes in there never comes out again! :-)
>
> I must admit I do not understand (or want to understand ;-)) C++
> syntax...

The Pascal equivalent would be:

MyDataset.First;
while not MyDataset.Eof do
begin
...
...
MyDataset.Next;
end;

> ...but I cant see why leaving the row pointer at the last record
> when returning eof would make any difference.

Eof usually means: immediately _past_ the end of input. Not only in
IBO, also in InterBase/Firebird themselves (or SQL, for that matter),
and when reading in files. As soon as you "are" Eof, there are no
valid data to fetch.

Leaving the row pointer at the last record when reaching Eof could be
done in two ways:

1. - While stepping through records using Next, Eof is false.
- When you reach the last record, Eof is still false.
- After another Next, you stay on the last record but Eof becomes
true.

This doesn't feel right to me, because now there are two states you
can be in while at the last record: one not Eof, and one Eof.

Also, what would you do upon a Prior if Eof is true and you are on
the last record:
a) Just turn off Eof and stay on the last record? This would be
logical because it preserves Prior-Next symmetry.
b) Turn off Eof and go to the last-but-one record? Also logical,
because after all Prior means "go back one record".

2. - While stepping through records using Next, Eof is false.
- When you reach the last record, Eof is turned on.
- Subsequent Nexts do nothing.

The problem with this is that now you can't use Eof anymore in a loop
condition. Because after a First, Eof will be true both for an
empty dataset and for a dataset with one record! More general:
you'll always miss the last record of the dataset. Unless you build
in extra checks within the loop and set a flag, but that makes
things uglier than they are now.

> The BDE did it OK - and at least that was not the reason IT has
> ended up in a black hole :-)

I've used the BDE too, long ago - did it really work that way? Did it
turn on Eof as soon as you were on the last record, or as soon as you
attempted to go beyond it?

> > Paul Vinkenoog, beyond your wildest EOF
> What a frightening thought ;-/

Yes, it's cold and lonely out there. This is where real men go - and
then wonder why ;-)


Greetings,
Paul Vinkenoog, shivering at 3K