Solved

Set one dataset filter

Posted on 1998-03-19
10
163 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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
 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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