![]() |
![]() |
|
![]() |
Beyond Help: setGenFilter by Tony McGuire Paradox Help on setGenFilter() Specifies conditions for including records in a TCursor. Syntax 1. setGenFilter ( [ idxName String, [ tagName String, ] ] criteria DynArray[ ] AnyType ) Logical 2. setGenFilter ( [ idxName String, [ tagName String, ] ] criteria Array[ ] AnyType [ , fieldId Array[ ] AnyType ] ) LogicalDescription setGenFilter specifies conditions for including records in a TCursor. Records that meet all the specified conditions are included, records that don't are filtered out. Unlike setRange, this method does not require an indexed table. setGenFilter must be executed before opening a table using a TCursor. In Syntax 1, a dynamic array (DynArray) named criteria specifies fields and filtering conditions. The index is the field name or number, and the item is the filter expression. The following code specifies criteria based on the values of three fields: criteriaDA[1] = "Widget" ; The value of the first field ; in the table is Widget. criteriaDA["Size"] = "> 4" ; The value of the field named ; Size is greater than 4. criteriaDA["Cost"] = ">= 10.95, < 22.50" ; The value of the field ; named Cost is greater ; than or equal to 10.95 ; and less than 22.50.If the DynArray is empty, all existing filter criteria are removed. In Syntax 2, an Array named criteria specifies filtering conditions, and an optional Array named fieldId specifies field names and numbers. If you omit fieldID, conditions are applied to fields in the order they appear in the criteria array (the first condition applies to the first field, the second condition applies to the second field, and so on). The following example specifies the same criteria as the example for Syntax 1. criteriaAR[1] = "Widget" criteriaAR[2] = "> 4" criteriaAR[3] = ">= 10.95, < 22.50" fieldAR[1] = 1 fieldAR[2] = "Size" fieldAR[3] = "Cost"If the Array is empty, all existing filter criteria are removed. For both syntaxes, idxName specifies an index name (Paradox and dBASE tables) and tagName specifies a tag name (dBASE tables only). If you use these optional items, the index (and tag) are applied to the TCursor before the filtering criteria. This method fails if the active record cannot be committed. Filtering on special characters If you are filtering on special characters, you must precede the number or literal value that can be interpreted as an operator (like ", /, \, -, +, =, etc.) with a backslash(\). In setgenfilter(), the filter criteria is put into a string and parsed to pick out numbers and operators for calculations. If the number or operator in the filter needs to be interpreted literally, it needs to be preceded by a backslash(\). For example to filter a table with the following records: 1st Baseand retrieve only those that start with "1st," the filter would look like the following: filter = "\\1st.."One backslash for the number and another to indicate the first backslash is not an escape sequence. Beyond Help First, the help above states "setGenFilter must be executed before opening a table using a TCursor." This is impossible, since setGenFilter() is utilized through an open tcursor (or table/uiObject). If, however, you use setGenFilter using a table variable, the statement "setGenFilter must be executed before opening a table variable using a TCursor" would be true. Don't let the On-line Help, or semantics, fool or confuse you. setGenFilter() differs greatly from setRange(). It is much slower, but also much more flexible. setRange() requires a keyed table, setGenFilter() can be applied to any table - keyed or not. setRange() and can operate with secondary indices, and values are set depending on the order that fields appear in the index; setGenFilter does not require that the table be keyed. Values are applied to whichever field name is reference in the criteria array's element name setRange() operates based on one or more exact matches, plus a range on one field. setGenFilter() can apply multiple calculated statements, just like a query (QBE), on any field(s) in the table. By itself, setGenFilter() operates much faster than a QBE when tables are local (on the desktop computer), and at about the speed of a QBE over a network (when the tables are stored on a server). A big difference is that you don't get a new table with setGenFilter. You get a 'restricted' or 'limited' view of the table; only records matching your criteria are displayed. However, because a new table isn't generated speed is enhanced. To use setGenFilter, you only need to declare a tcursor (or table, uiObject) variable and a dynamic array. The dynamic array element names must match (case-insensitive) the table field names that you will be setting your 'search' criteria on. In a script, this might look like: var tcAvailable TCursor dyAvailable DynArray[] String endVarNow, to set up your criteria, you need to establish some parameters. Just for starters, lets use the ZipCode field and the Price field to locate properties in the area (longint) and price range (longint) that our client wants to purchase a property. dyAvailable["ZipCode"]="\"90210\"" dyAvailable["Price"]=">=125000, <=145000"Note that the parameters are text values. Even though the fields are longint, the criteria are set as string values. The dynarray values are set using language nearly identical to a query (QBE). There are some differences, which are discussed below. You are now ready to open a table using the "tcAvailable" tcursor. tcAvailable.open(":aliasname:available.db") ; available.db stores currently ; available real estate listingsThen apply the parameters: tcAvailable.setGenFilter(dyAvailable)The record set that tcAvailable can now 'see' contains only those records in ZipCode "90210", between $125,000 and $145,000. Caveats to setting the criteria: setGenFilter looks at the values for your criteria to determine if there are calculation operators. Values starting with numbers must be preceded by "\\" to indicate the value should be treated literally (one slash to indicate that the second isn't an escape sequence, the second to indicate that the value that follows is to be treated as a literal value). Or, as I have done, enclose the value in quotes. If multiple zip codes were needed, you could use "\"90210\" or \"90265\"". Since setGenFilter can also be used with a uiObject, such as a tableframe, its power compounds. Let's say you have a form attached to "available.db", and a tableframe with the records in the table displaying on the top 2/3 of the form. At the form level, declare dynarray and uiObject variables: var dyAvailable DynArray[] String uiAvailable UIObject endVarI specify form level so you can perform various operations through pushbuttons or other constructs on the form, using the same variables, with the state of the tableframe persisting throughout the constructs. On the page's Open method, place code to connect the uiObject variable to the tableframe: uiAvailable.attach(available) ; available is the name of the tableframe ; which is a view of available.dbNow, place 3 unbound fields on the form: Zip, LowPrice, HighPrice. Next, place a pushbutton with the following code: dyAvailable["ZipCode"]=Zip dyAvailable["Price"]=">="+LowPrice+", <="+HighPrice ; set the criteria for your 'search' uiAvailable.setGenFilter(dyAvailable) ; apply the criteria to the tableframeInstantly, the tableframe on screen changes to reflect only those properties in the 90210 zip code, between LowPrice and HighPrice, inclusive. For Beyond Help on setRange(), see setRange For an explanation on combining the speed of setRange() with the flexibility of setGenFilter(), see Combining setRange and setGenFilter For some real world experiences that showcase the difference between using a Query and setRange, see The Need for Speed Discussion of this article |
![]() Feedback | Paradox Day | Who Uses Paradox | I Use Paradox | Downloads ![]() |
|
![]() The information provided on this Web site is not in any way sponsored or endorsed by Corel Corporation. Paradox is a registered trademark of Corel Corporation. ![]() |
|
![]() Modified: 15 May 2003 Terms of Use / Legal Disclaimer ![]() |
![]() Copyright © 2001- 2003 Paradox Community. All rights reserved. Company and product names are trademarks or registered trademarks of their respective companies. Authors hold the copyrights to their own works. Please contact the author of any article for details. ![]() |
![]() |
|