Board index » delphi » Locating first record in a range

Locating first record in a range

Suppose you have a database with a primary index consisting of two fields.
From what I understand of FindNearest(), you may not be pointed to the first
record in a range.  Is that correct?

For example, suppose you have a two-field database of LastName and
FirstName, and suppose your primary index is LastName:FirstName.  Suppose a
snippet of your database looks like below.

Jones  Ted
Smith  Albert
Smith  Bruce
Smith  Dorothy
Smith  Wayne
Turner  Dave

FindNearest(['Smith']) may not point to the "Smith  Albert" record, right?
Does it matter if your cursor is already pointing at, say, "Smith  Dorothy"
before calling FindNearest()?

The safest way to make sure that the cursor points to "Smith  Albert" is to
use:

SetRange(['Smith'], ['Smith']);
First;

Correct?

Thanks,

Bob Lincoln

 

Re:Locating first record in a range


Quote
Robert M. Lincoln wrote:

> Suppose you have a database with a primary index consisting of two fields.
> From what I understand of FindNearest(), you may not be pointed to the first
> record in a range.  Is that correct?

> For example, suppose you have a two-field database of LastName and
> FirstName, and suppose your primary index is LastName:FirstName.  Suppose a
> snippet of your database looks like below.

> Jones  Ted
> Smith  Albert
> Smith  Bruce
> Smith  Dorothy
> Smith  Wayne
> Turner  Dave

> FindNearest(['Smith']) may not point to the "Smith  Albert" record, right?
> Does it matter if your cursor is already pointing at, say, "Smith  Dorothy"
> before calling FindNearest()?

> The safest way to make sure that the cursor points to "Smith  Albert" is to
> use:

> SetRange(['Smith'], ['Smith']);
> First;

> Correct?

> Thanks,

> Bob Lincoln

I do not know about the Findnearest, but the setrange construct is
absolutely the way to go.

Menno

Re:Locating first record in a range


No. FindNearest postions you to the first record in the dataset that is
equal to or greater than the value you are searching for.

Bill

--

Bill Todd - TeamB
(TeamB cannot respond to email questions. To contact me
 for any other reason remove nospam from my address.)

Other Threads