Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread FindLastKey (revisited)
Wed, Mar 14 2007 10:54 AMPermanent Link

"Jose Eduardo Helminsky"
Tim

Sometime ago, I have asked to add a method in the TDBISamTable (and
TEDBTable) to find the last occurrence of any fields. I know if I create a
descending index works but if you can add this method it will be so nice. I
don´t know how hard it could be but I know how much it will give us.

RecordNumber  Field1 Field2
1                        1        Test one
2                        1        Eduardo
3                        1        Test two
4                        2        Eduardo
5                        2        Test three

Table.FindKey([1]) will move the record pointer to record 1

Table.FindLastKey([1]) will move the record pointer to record 3

Eduardo

Wed, Mar 14 2007 4:24 PMPermanent Link

Eryk Bottomley
Jose

> Table.FindLastKey([1]) will move the record pointer to record 3

Isn't this just:

function TDBISAMTable.FindLastKey(const KeyValues: array of const) :
Boolean;
var
  Mark : TBookMark;
begin
  Mark := GetBookMark;
  try
    SetRange(KeyValues,KeyValues);
    Result := not (Eof and Bof); {or maybe: Result := RecordCount > 0;}
    if Result then
      Last;
    CancelRange;
    if not Result then
      GotoBookMark(Mark);
  finally
    FreeBookMark(Mark);
  end;
end;

....untested ...and I'm very rusty at that sort of thing.

Eryk
Thu, Mar 15 2007 6:11 AMPermanent Link

"Jose Eduardo Helminsky"
Eryk

I have been using a function (method) like this but I think it DBISAM just
"walk" to the index is faster than this.
BTW, thanks for your help.

Eduardo

Fri, Mar 16 2007 3:44 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Eduardo,

<< I have been using a function (method) like this but I think it DBISAM
just "walk" to the index is faster than this. >>

It would only be slightly faster.  DBISAM would internally perform the same
steps as you.

--
Tim Young
Elevate Software
www.elevatesoft.com

Image