Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Paradox search

Status
Not open for further replies.

setitup

IS-IT--Management
Jul 30, 2003
17
ZA
Hi There,
I've got a simple paradox table with ITEMS and AMOUNT. Items is Alpanumeric and amount numeric. I want to be able to search these items with the old dBase GotoNearest procedure; but I can't figure it out.

How do I do it with a paradox table? ITEMS is a keyed field.

Thank you
Hennie
 
If you were working in an xBase table, you would use GotoKey or GotoNearest, but not in a Paradox table. Since you've got a Key on Items, you'll use either FindNearest or FindKey. If you have the full value of the Item you're searching for, you'll use FindKey like this:
Code:
  MyTable.FindKey('ITEMS',['Some Item Value']);
Where 'ITEMS' is the name of the field that's indexed and 'Some Item Value' is the value that you're searching for.

The FindNearest method looks similar:
Code:
  MyTable.FindNearest('ITEMS', ['Some Item']);
This will find the first value in ITEMS that starts with 'Some Item' or, if there is no value found, place the record pointer on the first record after where it would be.

It's set up this way so that you can search through indexes that have multiple fields involved. In Paradox, unlike xBase, indexes are not formed by adding fields together (i.e., Field1 + Field2), they're formed by selecting the individual fields for the index. In this way they are similar to client/server database indexes. FindKey and FindNearest are set up to work specifically on this kind of index. So, if you need to find a record in a table with a multi-field index, the method call will look like this:
Code:
  MyTable.FindKey('FIELD1;FIELD2', ['Field 1 value', 'Field 2 value']);

-Dell
 
Hilfy,

I don't think your examples are correct.

Assuming that setitup is using a TTable component then to find the record that has the key 'ITEM 1' the FindKey example would be something like:-
Code:
  MyTable.FindKey ( [ 'ITEM 1' ] );

If you wished to find the first record that has they key starting with 'ITE' then the FindNearest example would be:-
Code:
  MyTable.FindNearest ( [ 'ITE' ] );
Maybe you were confusing FindKey with Locate? With Locate you specify a list of field names and the field values. However with Locate, the specified fields need not be indexes.





Andrew
Hampshire, UK
 
Thanks Andrew & Dell,
I am using a TTable. While on the subject of tables. I want to filter this same table to show only items that contains certain values for instance I want to search these records for 'rep' and display them in a grid:

adcodol
reprinol
inreprolene
syndol
indorep

The filtered table should display only the 2,3 & 4th lines. Please advise again.

Hear from you soon
 
Write an OnFilterRecord event handler for the TTable. It should look something like this:
Code:
procedure TForm1.Table1FilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
  Accept := Pos('rep',Table1.FieldByName('items').AsString)>0;
end;
You need to set the Filtered property to TRUE for the event handler to take effect.


Andrew
Hampshire, UK
 
Towerbase,
duh! I feel stupid...actually, it's been quite a while (several years) since I did P'dox stuff - I've been working with Oracle and haven't used TTables in a while. Thanks for picking up on that!!

-Dell
 
Hi, me again,

All fine, but now every time I use a filter it uses only this specified one. How do I turn it off and create other filters in this manner, delphi help says you can create multiple by coding, but how? It doesnt give more information and how-to's.


 
You could set a variable that's global to the form's unit (I'd put it in the Private declaration.) You set that variable to the value you want to search for. Then, in your OnFilterRecord event handler, use that variable instead of 'rep' in the call to Pos. Assuming a variable name of sFilterVal, it would look something like this:
Code:
procedure TForm1.Table1FilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
  Accept := Pos(sFilterVal,Table1.FieldByName('items').AsString)>0;
end;

-Dell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top