Board index » delphi » Any tricks for filtering on lookup fields?

Any tricks for filtering on lookup fields?

I am using Delphi 2.01, I have four tables, one transaction table and three
look-up tables.  Now I created persistent fields in the transaction table
some with calculated values and also including those fields with a value
based on the other three look-up tables.

Now I want to filter the transaction tables based on the lookup values and
I tried using the OnFilterRecord event of the transaction table.  The
problem is, the Delphi help files says that filtering can't be done on the
Look-up values, however, it was suggested that it is possible to filter on
calculated fields. Can somebody give examples of these? Now I tried
filtering using the OnFilterRecord event based on the calculated values and
it still didn't work.  The reason is that the OnFilterRecord event gets
called first before the OnCalcField event. Now my questions to the gurus
out there are:

Without resorting to queries,
1. Is there a way to filter on the look-up values? If yes, then how?
2. Is there a way to make the OnCalcField event execute first before the
OnFilterRecord event of a table? How do we do this step by step?

I will appreciate very much your kind response.

 

Re:Any tricks for filtering on lookup fields?


Quote
"Joselito G. Real" wrote:

> I am using Delphi 2.01, I have four tables, one transaction table and three
> look-up tables.  Now I created persistent fields in the transaction table
> some with calculated values and also including those fields with a value
> based on the other three look-up tables.

> Now I want to filter the transaction tables based on the lookup values and
> I tried using the OnFilterRecord event of the transaction table.  The
> problem is, the Delphi help files says that filtering can't be done on the
> Look-up values, however, it was suggested that it is possible to filter on
> calculated fields. Can somebody give examples of these? Now I tried
> filtering using the OnFilterRecord event based on the calculated values and
> it still didn't work.  The reason is that the OnFilterRecord event gets
> called first before the OnCalcField event. Now my questions to the gurus
> out there are:

> Without resorting to queries,
> 1. Is there a way to filter on the look-up values? If yes, then how?
> 2. Is there a way to make the OnCalcField event execute first before the
> OnFilterRecord event of a table? How do we do this step by step?

I haven't checked if you are right, but if the OnFilterRecord event really
fires first, then what I would do is:

1) In the OnFilterRecord event, perform the calculations normally
   done in the OnCalcFields event - can also be used for looking
   field values up. Then filter on the calculated/looked up values.
   If the filter condition accepts the values, store them in some
   private fields/variables.
2) In the OnCalcFields event just use the already calculated
   values that you have stored in your (private) variables/fields.

Hope that helps.

Karl

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   Karl Waclawek
   KD Soft Inc.
 * Phone:  (905) 579-3443
 * E-Mail: wacla...@idirect.com

Re:Any tricks for filtering on lookup fields?


Karl Waclawek <kwac...@thestar.ca> wrote in article
<36489416.8674C...@thestar.ca>...
Quote
> 1) In the OnFilterRecord event, perform the calculations normally
>    done in the OnCalcFields event - can also be used for looking
>    field values up. Then filter on the calculated/looked up values.

......

I can do the calculations alright, but how do you look up field values on
other tables under the OnfilterRecord event of another table?

Re:Any tricks for filtering on lookup fields?


Quote
"Joselito G. Real" wrote:

> Karl Waclawek <kwac...@thestar.ca> wrote in article
> <36489416.8674C...@thestar.ca>...
> > 1) In the OnFilterRecord event, perform the calculations normally
> >    done in the OnCalcFields event - can also be used for looking
> >    field values up. Then filter on the calculated/looked up values.
> ......

> I can do the calculations alright, but how do you look up field values on
> other tables under the OnfilterRecord event of another table?

Well, you have to do in code what is normally done by defining
a lookup field. Just perform a GoToKey or FindKey on the table whose
fields you need to look up, then simply read the field value in
the current record.

Karl

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   Karl Waclawek
   KD Soft Inc.
 * Phone:  (905) 579-3443
 * E-Mail: wacla...@idirect.com

Other Threads