Solved

Runtime Filter procedure

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…
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 …

948 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

19 Experts available now in Live!

Get 1:1 Help Now