Delphi 2009 Table findnext

gerhard9121 used Ask the Experts™

Using Delphi 209, Titan and InfoPower. I doing the following at runtime:

Select a table from a list.
Select a index from a list.
Display a record from the table.
Change more than one of the key fields values.

Now the problem. I can't at runtime find the record nearest to the changed data.

procedure TfrmDataInspector.bSearchClick(Sender: TObject);
  LocateValues : Variant;
  LocateFields: String;
  I: Integer;
  LocateFields := tbTemp.IndexFieldNames;
  LocateValues := VarArrayCreate([0, tbTemp.IndexFieldCount - 1],varVariant);
  for i:= 0 to tbTemp.IndexFieldCount - 1 do
      LocateValues[i]:= tbTemp.IndexFields[i].AsString;
  if tbTemp.State <> dsBrowse then
  if tbTemp.Locate(LocateFields,LocateValues,[loCaseInsensitive,loPartialKey]) then

Open in new window

The Locate only works if all he keys are completed correctly.

The FindNearest give a conversion error. How do I pass the Parameters of mix types to the procedure

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Geert GOracle dba
Top Expert 2009

it's easier using a Query

difference between table and query:
using a table, all data is loaded into memory first, and then the search performed
using a query, the searchcriteria are specified in the sql text and only the matching dataset is returned across the network
(you don't need to index each search field)

it's more difficult if you don't want exact matches
but then again, what is a not so exact match ...
Geert GOracle dba
Top Expert 2009

not really sure what your database type is.

query for finding a match or almost match:

select *
from tbTemp t
  case when upper(column1) like upper(:value1) then '1' else '' end ||
  case when upper(column2) like upper(:value2) then '1' else '' end ||
  case when upper(column3) like upper(:value3) then '1' else '' end like '%1%';

|| is concatenation of string in oracle


Sorry I did not mention but the data is stored in Btrieve (not pervasive) database. Don't think it caters for SQL query.

How does Infopower pass the Locate Values as a Array of Constant to there FindNearest procedure
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

Geert GOracle dba
Top Expert 2009

don't have any experience with Btrieve

Using Delphi 209, Titan and InfoPower
i new what Delphi2009 was for but i've no clue what Titan is
And InfoPower is just a hint of clue

any reference to Titan and InfoPower ?

and BTrieve (not Pervasive) ?
>> this would state differently
Geert GOracle dba
Top Expert 2009

can't even find BTrieve documentation without a login
> then again, they stopped BTrieve 16 years ago
President and Btrieve Guru
The Btrieve interface is alive and well as part of the Pervasive database engine, with the latest version, v11.20 being released just last month.

One of the problems, I think, is that you are changing a key value.  This makes it very hard to retain your existing positioning in the file, also known as "currency", by saving the pointers to the previous and next records.  When you are navigating a Btrieve record set, the currency always keeps track of the previous and next record on your key path.  However, when you change the data on the key and issue an update statement, your positioning on the key path is changed or lost.

There are two solutions for native Btrieve API developers:
1) Issue a sequence like this:
    GetNext (This gets the next record in the list)
    Position=GetPosition (this saves the position of the next record)
    GetPrevious (This puts you back on the original record)
    Update (This changes your currency)
    GetDirect(Position) (This puts you back on the NEXT record, saved above)
This is a lot of work, which is why the NCC Update was added to Btrieve 6.
2) Issue an NCC Update.  This works just like a regular update, but it saves your currency pointers (to the next and previous records), so that you can simply issue a GetNext afterwards.  To use the NCC Update, set the key number to -1 before the Update.  (Don't forget to set it back afterwards, or you'll get errors.

Now, the Titan interface is not exactly native Btrieve, but you may be able to find something in the docs that discuss this feature in there, too.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial