Board index » delphi » How to filter/set range on a TTable?

How to filter/set range on a TTable?

Hello,

I'm working on an app in which I display a list of records from a db,
from TTable component to a DBGrid. I have the following primary index
(the data is a book list)

fields:
        id (short int)          - book seller id
        row (short int)         - row number in seller's (paper) catalog
        code (char)             - type of book as single-letter codes

Normally I show all the books from a single seller by using
SetRangeStart and SetRangeEnd on the 'id' field. I got that to work
ok, but now I'm mystified -- I want to have the user be able to
optionally view a subset of the books, depending on the 'code'
field. In other words, I want to show (for example) all the books from
seller id 7 that have the code 'X' (no restriction needed or wanted on
'row'). So far I haven't managed to figure out a way to do the trick,
any and all help would be greatly appreciated.

...and no, I don't want to use an SQL query. The book list is big
(around 1500 books per seller code) and I need to do searches in
it. GotoKey is nice and fast, hand-searching an SQL query result isn't
:-)

//Petri

 

Re:How to filter/set range on a TTable?


In article <ovkn36jx94g....@lk-hp-26.hut.fi>, Petri.Wess...@hut.fi says...

Quote
> I'm working on an app in which I display a list of records from a db...
> I have the following primary index (the data is a book list)

>fields:
>        id (short int)          - book seller id
>        row (short int)         - row number in seller's (paper) catalog
>        code (char)             - type of book as single-letter codes

>I want to have the user be able to
>optionally view a subset of the books, depending on the 'code'
>field. In other words, I want to show (for example) all the books from
>seller id 7 that have the code 'X' (no restriction needed or wanted on 'row')

Since you mentioned db file I assume you're wortking with Paradox format.
To accomplish that task you should create index on both ID and CODE
fields like this:

 AddIndex('YourIndexName', 'ID;CODE', YourOptions);

The parameters for SetRange procedure are declared in Delphi help as
array of const so that you may use the following statement for viewing
the desired subset of records:

 YourTable.SetRange([7,'X'], [7,'X']);

--
Vitaly Monastirsky
--
vit...@vdl.t.u-tokyo.ac.jp
http://jgarner.at.utm.edu/jobs/vitres.htm

Other Threads