Solved

Runtime Filter procedure

Posted on 1997-05-18
4
364 Views
Last Modified: 2010-04-04
In a D2 program, in a Search routine using a DBGrid tied to any one of several Paradox tables -
I'm writing a generic Search routine to display ONLY those records which match certain criteria.  The grid is standard, but the table connected to it could change, so I can't just set the OnFilterRecord event handler of any ONE DataSet (Table).

Specifically, I want to be able to filter the record on more than just the ">,<,=,<>" combinations.  I'd like to be able to display a record because it has, for example, the word 'Mixer' in the record's "Description" field.

Bottom line- I need a way to connect a filter procedure (I can handle writing that) to the "OnFilterRecord" event of whichever table is connected to the grid AT THE TIME I'm doing the search...

So- how do I set the OnFilterRecord event handler AT RUN TIME?
0
Comment
Question by:Raven1155
  • 2
4 Comments
 
LVL 2

Expert Comment

by:javiertb
Comment Utility
You'll be able to display a record that has, for example, the word 'Mixer' in the record's "Description" field just by doing the following in the OnFilterRecord:

begin
   if (Pos('Mixer',Table1DESCRIPTION.Value)>0) then
      Accept:=True
   else
      Accept:=False;
end;

This works. (Yes, Sperling, I've already TESTED it) ;-)

Anyway, if you still want to use your own procedure you have to assign an identical type procedure to the table OnFilterRecord one.
Table1.OnFilterRecord:=MyFilterRecordProc;

procedure TForm1.MyFilterRecord(DataSet: TDataSet; var Accept: Boolean);
begin
// Your procedure code
end;
0
 

Author Comment

by:Raven1155
Comment Utility
I asked "How do I set the OnFilterRecord event handler AT RUN TIME?"  This question has not been answered!

"Table1.OnFilterRecord:=MyFilterRecordProc; " generates, as it obviously would,  a compiler error pointing out that "MyFilterRecordProc" is undefined.

I can't just set the OnFilterRecord event to the procedure, as in-
"Table1.OnFilterRecord:=MyFilterRecord;" {to use your procedure name}

The question still remains, >>HOW<< do I define MY procedure as the one the Table should use to filter records?!?!?!?!?!?!?!?!?

Are you saying that I need to declare my own TFilterRecordEvent descendent?  If I do this, how do I "connect" it to the Table's "OnFilterRecord" and/or to my filter routine?!?!

BTW- Thanks for the example code about finding 'Mixer' in DESCRIPTION, but that's not the question!
0
 
LVL 3

Accepted Solution

by:
sperling earned 100 total points
Comment Utility
Declare a procedure in e.g. the private section of a form. This procedure *must* be declared "inside" a class, it cannot be a standalone method.
.
.
.
private
  procedure FilterRecord (Dataset : TDataset;
    var Accept : BOOLEAN);

public
.
.


In this methods implementation, write your filter code.

If you've got a grid e.g. DBGrid1, here's how to set the handler:
  DBGrid1.DataSource.DataSet.OnFilterRecord := FilterRecord;

You'll always have to set DataSet.Filtered := TRUE, and DataSet.Filter blank.

Be aware that as soon as you remove the filter from the table by setting DataSet.OnFilterRecord to nil or DataSet.Filtered to FALSE, your grid will (if still connected to the table) revert to showing all records in the table. This is simply how Delphi's DB controls are designed.

javiertb: Great. Keep up the good work, let's have some competition here ;)


Regards,

Erik.
0
 

Author Comment

by:Raven1155
Comment Utility
Excellent!!  No doubt that's what the prior expert MEANT, but the way YOU put it, I got it!

THANKS!
 Jim 8^)
0

Featured Post

Free Trending Threat Insights Every Day

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

7 Experts available now in Live!

Get 1:1 Help Now