?
Solved

Runtime Filter procedure

Posted on 1997-05-18
4
Medium Priority
?
400 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
[X]
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
  • 2
4 Comments
 
LVL 2

Expert Comment

by:javiertb
ID: 1336442
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
ID: 1336443
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 200 total points
ID: 1336444
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
ID: 1336445
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

765 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