Board index » delphi » filter

filter

I am using Delphi 2.

I have a database (paradox 5.0) with two key fields. The first is a character
field (NAME) and the second is a number (DISK).

I want to allow the user to select a number from the number field and thereby
filter the dbGrid table displayed such that only records with that number in the
field appear in the grid. The user will also be able to remove the filter.

I have tried setrange in what I feel is the correct way but all that happens is
that all records disappear from the grid....

Do I need to 'switch' to the secondary field index? If so, how?

I'm very confused by what should be a very simple action on a database.

Help!!!

Here is the code snippet...

procedure Tcatform.FilterClick(Sender: TObject);
var
   dsk: word;
   s: string;
begin
   { mask all but selected disk }
   { disk is determined by current selection }
   { inactive if filtering is already on }
   dsk:=table.fieldbyname('DISK').asinteger;
   table.cancelrange;
   table.setrangestart;
   table.fieldbyname('DISK').asinteger:=dsk;
   table.setrangeend;
   table.fieldbyname('DISK').asinteger:=dsk;
   table.applyrange;
   table.first;
   Filter.Enabled:=FALSE;     { these toggle the related menu items }
   NoFilter.Enabled:=TRUE;
end;

procedure Tcatform.NoFilterClick(Sender: TObject);
begin
   { removes disk filtering }
   { inactive if no filtering currently active }
   table.cancelrange;
   table.setrangestart;
   table.fieldbyname('DISK').asinteger:=1;
   table.setrangeend;
   table.fieldbyname('DISK').asinteger:=1000;  { 1000 is max }
   table.applyrange;
   table.first;
   NoFilter.Enabled:=FALSE;;     { these toggle the related menu items }
   Filter.Enabled:=TRUE;
end;

 

Re:filter


Quote
sje@REMOVE_THIS.pathcom.com (Simon Ewins) wrote:
>I am using Delphi 2.

>I have a database (paradox 5.0) with two key fields. The first is a character
>field (NAME) and the second is a number (DISK).

>I want to allow the user to select a number from the number field and thereby
>filter the dbGrid table displayed such that only records with that number in the
>field appear in the grid. The user will also be able to remove the filter.

>I have tried setrange in what I feel is the correct way but all that happens is
>that all records disappear from the grid....

>Do I need to 'switch' to the secondary field index? If so, how?

>I'm very confused by what should be a very simple action on a database.

>Help!!!

For the setrange to work, you must first select the index, and then
apply the setrange.

Table1.indexfieldnames := 'DISK';
Table1.setrange(Dskini,Dskend);
Table1.refresh

You can also use the Onfilter event.

Regards
Jose OStos

Other Threads