Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Set one dataset filter

Posted on 1998-03-19
10
164 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

861 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