Board index » delphi » TTable.SetRange does not work the way I expect

TTable.SetRange does not work the way I expect

Hi all

I am working with Delphi 2 under Win2000 and I wonder if the SetRange
function of the component TTable does work the right way.

My data are stored in a Paradox 5.0 Table which has a key column (primary
key, autoincrement) and 2 String columns.
Table: TableData [Key:Autoincrement, OrderNr: String, LineNr : String].

To filter the table according OrderNr and/or LineNr I have defined an index
called 'OrderNrLineNr' which consists out of the column OrderNr and LineNr.

If I set a filter for the two columns with the SetRange method of the TTable
component everything is ok. I get the rows which I expect.

with TableData do
begin
   IndexName := 'OrderNrLineNr';
   SetRange(['A-001', 'Line1'], ['A-001', 'Line6']);
end;

but if I set for the column 'OrderNr' the whole range I get all the records
of the data set instead only the records with the LineNr >= 'Line1' and
LineNr <= 'Line6'.

with TableData do
begin
   IndexName := 'OrderNrLineNr';
   SetRange([null, 'Line1'], ['Zzzzzzzzz', 'Line6']);
end;

What is going wrong? Is the applied range not an 'and-combination' of the
given parameters?

Does anyone have an idea to solve this problem?
(The filter function of the TTable component is not an option for me because
it is too slow.)

Regards
Bruno

 

Re:TTable.SetRange does not work the way I expect


1. your question would better fit in .database.desktop (not that it matters
to me, but you'd surely get better responses)
2. SetRange works on indexes, so for each range you must switch to correct
index. With compound index (=combined of two or more fields) the first field
has higher priority than second meaning you can't skip the first field to
set range on second field only. For this you'd have to create another index
for second field and switch to that before use. This is the same with
Paradox and SQL servers.

So, create an index for LineNr.

--
Robert

Quote
Bruno Gebert wrote in message <3b26462b$1_1@dnews>...
>Hi all

>I am working with Delphi 2 under Win2000 and I wonder if the SetRange
>function of the component TTable does work the right way.

>My data are stored in a Paradox 5.0 Table which has a key column (primary
>key, autoincrement) and 2 String columns.
>Table: TableData [Key:Autoincrement, OrderNr: String, LineNr : String].

>To filter the table according OrderNr and/or LineNr I have defined an index
>called 'OrderNrLineNr' which consists out of the column OrderNr and LineNr.

>If I set a filter for the two columns with the SetRange method of the
TTable
>component everything is ok. I get the rows which I expect.

>with TableData do
>begin
>   IndexName := 'OrderNrLineNr';
>   SetRange(['A-001', 'Line1'], ['A-001', 'Line6']);
>end;

>but if I set for the column 'OrderNr' the whole range I get all the records
>of the data set instead only the records with the LineNr >= 'Line1' and
>LineNr <= 'Line6'.

>with TableData do
>begin
>   IndexName := 'OrderNrLineNr';
>   SetRange([null, 'Line1'], ['Zzzzzzzzz', 'Line6']);
>end;

Re:TTable.SetRange does not work the way I expect


Quote
In article <3b26462b$1_1@dnews>, Bruno Gebert wrote:
> but if I set for the column 'OrderNr' the whole range I get all the records
> of the data set instead only the records with the LineNr >= 'Line1' and
> LineNr <= 'Line6'.

SetRange provides a window into the dataset and provides *contiguous*
records. In practice, this means that you can only vary the values of the
last field in a multi-field index.

Mike Orriss (TeamB and DevExpress)

Other Threads