Solved

Set one dataset filter

Posted on 1998-03-19
10
162 Views
Last Modified: 2010-04-06
Hello ALL,

I need to setup the filter property of one dataset in the run time.
I want to select between three values:
catg = 'p'
catg = 'c'
catg = 'o'
Where:                   catg is the field name in the dataset (ttable),
                   p,c and o are the values I want to select.
I'm using one TRadioGroup to select and:

case TRadioGroup.ItemIndex of
0 : '????????'; { set catg = 'p'}
1 : '????????'; { set catg = 'c'}
2 : '????????'; { set catg = 'o'}
end;

The code I'm using doesn't works. Any suggestion?

Regards....
0
Comment
Question by:sergio_2001
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 1

Expert Comment

by:RJENKINS
ID: 1360622
What is the Exact Coding ?
the code you have given is not real code
is it like below
(note double-single quotes)

case TRadioGroup.ItemIndex of
0: DateSet.Filter := ' catg = ''p'' ';
0: DateSet.Filter := ' catg = ''c'' ';
0: DateSet.Filter := ' catg = ''o'' ';

Have you set the DataSet.Filtered to True

RCJ
0
 
LVL 1

Expert Comment

by:RJENKINS
ID: 1360623
should be
case TRadioGroup.ItemIndex of
0: DateSet.Filter := ' catg = ''p'' ';
1: DateSet.Filter := ' catg = ''c'' ';
2: DateSet.Filter := ' catg = ''o'' ';

RCJ
0
 

Expert Comment

by:bijoyn
ID: 1360624
Hi There,

I am putting up an e.g. that I tried out. It has a radiogroup with option as 'Active' and 'InActive'. I have a datasource and a Query component on the form. There is a field called 'ActiveInd' which can have values 'Y' or 'N'. what I do is onclick of a button, I set the filter property to 'Y' or 'N' depending on the radio item selected and open the query. The results are shown in a DBGrid.

--------------------------

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, StdCtrls, DBCtrls, DB, DBTables, ExtCtrls, Grids, DBGrids;

type
  TForm1 = class(TForm)
    DataSource2: TDataSource;
    Query2: TQuery;
    DBGrid1: TDBGrid;
    RadioGroup1: TRadioGroup;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
   Query2.Filter  := '';
   Query2.Close;
   if RadioGroup1.ItemIndex = 0 then
      Query2.Filter  := 'ACTIVEIND = ' + '''' + 'Y' + ''''
   else
      Query2.Filter  := 'ACTIVEIND = ' + '''' + 'N' + '''';
   Query2.Open;
end;

end.

-------------------------------

I hope this helps.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360625
Oops didn't saw already that much people had given an answer :

Heck here is my answer :

Put a table, datasource, dbgrid and radiogroup on the form
Put values MED, HIGH, LOW in the radiogroup.
Take DBDEMOS as Database and  Clients.DBF as table.

Link table to datasource and datasource to grid. copy this example to your unit and run!

click on the radiogroup and see the results.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, Grids, DBGrids, DB, DBTables;

type
  TForm1 = class(TForm)
    Table1: TTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    RadioGroup1: TRadioGroup;
    procedure RadioGroup1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
 case RadioGroup1.ItemIndex of
  0 : Table1.Filter := 'Risk_Level = ''MED''';
  1 : Table1.Filter := 'Risk_Level = ''HIGH''';
  2 : Table1.Filter := 'Risk_Level = ''LOW''';
 end;
  showmessage(Table1.Filter);
 Table1.Filtered := True;
end;

end.


Bye,
Regards, Zif.
0
 

Author Comment

by:sergio_2001
ID: 1360626
Hi All,

I'll evaluate all answers...
How can select just one correct answer ???

Thanks....
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:RJENKINS
ID: 1360627
Ask that person to submit their comment as an answer
and then award the points to them
0
 

Expert Comment

by:bijoyn
ID: 1360628
Hi Sergio,

Which of the solutions are working for u ???

Bijoy
0
 

Author Comment

by:sergio_2001
ID: 1360629
Hi all,

Both bijoyn and ZifNab answer works. However ZifNab's answer is more easy to use.
So send me the answer.

Thanks...
0
 

Author Comment

by:sergio_2001
ID: 1360630
One correction,

RJENKINS answer I suppose works too. There are some confusion with the quotation marks. And his answer was the first one. So please send me the answer.

Thanks...

0
 
LVL 1

Accepted Solution

by:
RJENKINS earned 20 total points
ID: 1360631
Try code like below

case TRadioGroup.ItemIndex of
  0: DateSet.Filter := ' catg = ''p'' ';
  1: DateSet.Filter := ' catg = ''c'' ';
  2: DateSet.Filter := ' catg = ''o'' ';
end;
Set the DataSet.Filtered to True

RCJ
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 73
LAN or WAN ? 11 82
Create a path if not exists 7 69
how can i search if string exist in array ? 3 50
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now