Solved

Runtime Filter procedure

Posted on 1997-05-18
4
388 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 100 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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