Solved

Set one dataset filter

Posted on 1998-03-19
10
161 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

10 Experts available now in Live!

Get 1:1 Help Now