Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Runtime Filter procedure

Posted on 1997-05-18
4
Medium Priority
?
409 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

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

598 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