Board index » delphi » HELP - Filter property doesn't work!!!

HELP - Filter property doesn't work!!!

I've tried everything but filter property doesn't work. I have Edit field,
Button and DBGrid. Everything is OK if I enter this directly in Table1
property, Filter:
NAMEANDSUR = 'al*' and change Filtered property to TRUE. But if I put this
like program in a button procedure it doesn't work. It looks like this:

procedure TMyProg.Button3Click(Sender: TObject);
begin
Table1.Filter := 'NAMEANDSUR = 'ax*'';
Table1.Filtered := True;
end;

My final goal is to filter every record in my database where I can find the
word that I type in Edit field no matter in which field of the record it was
found. But how can I even think about that if this simple program doesn't
work.
In Delphi HELP under the heading "Setting the filter property" I found the
following line :
Dataset1.Filter := Edit1.Text;

I tried this and everything else I found on this page, but I also get error
messages. What am I doing wrong. What is the easiest way to do this?
Thank you in advance!

Etan

 

Re:HELP - Filter property doesn't work!!!


Try

Table1.filtered := false;   // stop the filter first
Table1.filter := 'ax*';       // The contents of the edit1.text is text, not
an assignment or such...
Table1.Filtered := True;  // Should start the filter again

--
Paul Lagasse'
The Better Byte Software Company
http://www.betbyte.com

Quote
Etan <e...@freemail.org.mk> wrote in message

news:3a834b7a$1@news.mt.net.mk...
Quote
> I've tried everything but filter property doesn't work. I have Edit field,
> Button and DBGrid. Everything is OK if I enter this directly in Table1
> property, Filter:
> NAMEANDSUR = 'al*' and change Filtered property to TRUE. But if I put this
> like program in a button procedure it doesn't work. It looks like this:

> procedure TMyProg.Button3Click(Sender: TObject);
> begin
> Table1.Filter := 'NAMEANDSUR = 'ax*'';
> Table1.Filtered := True;
> end;

> My final goal is to filter every record in my database where I can find
the
> word that I type in Edit field no matter in which field of the record it
was
> found. But how can I even think about that if this simple program doesn't
> work.
> In Delphi HELP under the heading "Setting the filter property" I found the
> following line :
> Dataset1.Filter := Edit1.Text;

> I tried this and everything else I found on this page, but I also get
error
> messages. What am I doing wrong. What is the easiest way to do this?
> Thank you in advance!

> Etan

Re:HELP - Filter property doesn't work!!!


Etan,

    I had the same problem at first till I discovered that I didn't have
enough quotes in my := to statement e.g.:

procedure TMainForm.RadioButton12Click(Sender: TObject);
begin
     with DM.Postable do
     begin
          Filtered := True;
          Filter := 'Status=''Pending''';
     end;
end;

and I never had to turn the filter off just changed the := statement, works
great!

Happy Programming

Deke

Quote
"Etan" <e...@freemail.org.mk> wrote in message

news:3a834b7a$1@news.mt.net.mk...
Quote
> I've tried everything but filter property doesn't work. I have Edit field,
> Button and DBGrid. Everything is OK if I enter this directly in Table1
> property, Filter:
> NAMEANDSUR = 'al*' and change Filtered property to TRUE. But if I put this
> like program in a button procedure it doesn't work. It looks like this:

> procedure TMyProg.Button3Click(Sender: TObject);
> begin
> Table1.Filter := 'NAMEANDSUR = 'ax*'';
> Table1.Filtered := True;
> end;

> My final goal is to filter every record in my database where I can find
the
> word that I type in Edit field no matter in which field of the record it
was
> found. But how can I even think about that if this simple program doesn't
> work.
> In Delphi HELP under the heading "Setting the filter property" I found the
> following line :
> Dataset1.Filter := Edit1.Text;

> I tried this and everything else I found on this page, but I also get
error
> messages. What am I doing wrong. What is the easiest way to do this?
> Thank you in advance!

> Etan

Re:HELP - Filter property doesn't work!!!


Are you trying to filter all names starting with ax ? In that case you
should use:

Table1.Filter := 'NAMEANDSUR LIKE ''ax%''';
Table1.Filtered := True;

"Etan" <e...@freemail.org.mk> schreef in bericht
news:3a834b7a$1@news.mt.net.mk...

Quote
> I've tried everything but filter property doesn't work. I have Edit field,
> Button and DBGrid. Everything is OK if I enter this directly in Table1
> property, Filter:
> NAMEANDSUR = 'al*' and change Filtered property to TRUE. But if I put this
> like program in a button procedure it doesn't work. It looks like this:

> procedure TMyProg.Button3Click(Sender: TObject);
> begin
> Table1.Filter := 'NAMEANDSUR = 'ax*'';
> Table1.Filtered := True;
> end;

> My final goal is to filter every record in my database where I can find
the
> word that I type in Edit field no matter in which field of the record it
was
> found. But how can I even think about that if this simple program doesn't
> work.
> In Delphi HELP under the heading "Setting the filter property" I found the
> following line :
> Dataset1.Filter := Edit1.Text;

> I tried this and everything else I found on this page, but I also get
error
> messages. What am I doing wrong. What is the easiest way to do this?
> Thank you in advance!

> Etan

Re:HELP - Filter property doesn't work!!!


This is right out of the Help file... Maybe you are just missing the '+'.

To create a filter using the Filter property, set the value of the property
to a string that contains the filter conditions. The string contains the
filter's test condition. For example, the following statement creates a
filter that tests a dataset's State field to see if it contains a value for
the state of California:

Dataset1.Filter := 'State = ' + QuotedStr('CA');

You can also supply a value for Filter based on the text entered in a
control. For example, the following statement assigns the text in an edit
box to Filter:

Dataset1.Filter := Edit1.Text;

You can, of course, create a string based on both hard-coded text and data
entered by a user in a control:

Dataset1.Filter := 'State = ' + QuotedStr(Edit1.Text);

After you specify a value for Filter, to apply the filter to the dataset,
set the Filtered property to True.
You can also compare field values to literals, and to constants using the
following comparison and logical operators:

Operator Meaning
< Less than

Quote
> Greater than
>= Greater than or equal to

<= Less than or equal to
= Equal to
<> Not equal to
AND Tests two statements are both True
NOT Tests that the following statement is not True
OR Tests that at least one of two statements is True
By using combinations of these operators, you can create fairly
sophisticated filters. For example, the following statement checks to make
sure that two test conditions are met before accepting a record for display:

(Custno > 1400) AND (Custno < 1500);

Note: When filtering is on, user edits to a record may mean that the record
no longer meets
a filter's test conditions. The next time the record is retrieved from the
dataset, it may therefore "disappear." If that happens, the next record that
passes the filter condition becomes the current record.

Quote
M.H. Avegaart <avegaartNOS...@mccomm.nl> wrote in message

news:960dt4$ocn$1@porthos.nl.uu.net...
Quote
> Are you trying to filter all names starting with ax ? In that case you
> should use:

> Table1.Filter := 'NAMEANDSUR LIKE ''ax%''';
> Table1.Filtered := True;

> "Etan" <e...@freemail.org.mk> schreef in bericht
> news:3a834b7a$1@news.mt.net.mk...
> > I've tried everything but filter property doesn't work. I have Edit
field,
> > Button and DBGrid. Everything is OK if I enter this directly in Table1
> > property, Filter:
> > NAMEANDSUR = 'al*' and change Filtered property to TRUE. But if I put
this
> > like program in a button procedure it doesn't work. It looks like this:

> > procedure TMyProg.Button3Click(Sender: TObject);
> > begin
> > Table1.Filter := 'NAMEANDSUR = 'ax*'';
> > Table1.Filtered := True;
> > end;

> > My final goal is to filter every record in my database where I can find
> the
> > word that I type in Edit field no matter in which field of the record it
> was
> > found. But how can I even think about that if this simple program
doesn't
> > work.
> > In Delphi HELP under the heading "Setting the filter property" I found
the
> > following line :
> > Dataset1.Filter := Edit1.Text;

> > I tried this and everything else I found on this page, but I also get
> error
> > messages. What am I doing wrong. What is the easiest way to do this?
> > Thank you in advance!

> > Etan

Other Threads