Subject Re: [firebird-support] last record of query
Author Woody
From: "Sergio H. Gonzalez" <shg_sistemas@...>
> Delphi 6, Interbase Express.
>
> Hello
> Is there way to know if I'm on the last record of a query? I need to do
> something special (in a report) on the last record. I can't check for Eof,
> because It's false until the next skip on the table.
>
> So far I'm using
>
> function LastRecord(t:TIBQuery): boolean;
> begin
> t.Next;
> result := t.Eof;
> t.Prior;
> end;
>

If you are at the EOF, then Next does not change the position of the record
pointer. It stays on the last record. However, in your code, you aren't
testing to see if you are at the EOF before performing the Prior.

There are 3 ways to do this (IMO):

1. The way you are doing it but I would add this test:
if not result then
t.Prior;

2. Get a record count before starting to print and check the printed count
against that.

3. Do a separate query to get the ID of the last record using a reverse
ordering (DESC) and compare that.

HTH
Woody (TMW)