Mega Code Archive

 
Categories / Delphi / ADO Database
 

Table Filtering

Title: Table Filtering Question: How to filter a paradox or compatible table. Answer: The filter property of TTable is very handy when you want to filter a table for instance when somebody types in a surname which must filter a table. This is handy when writing something like a address book where the more information the user type the less fields or entries he/she sees when adjusting the filter making the search in the users eyes much more userfriendly. To filter a table with the following fields: Name,Surname:String Number:Integer; Table1.Filtered:=False; Table1.Filter:='Name='van der'; Table1.Filtered:=True;\ A few tips. If a query is run on the table it will only execute on the fields that is visible after the filter is executed. This if the filter is Table1.Filter:='Name='van der'; then the query will only return results were the name were equal to 'van der' You can insert a asteriks into a search eg Table1.Filter:='Name='van der*'; which will find anything that starts simmarly Remember to always make the filterd property true and when you are searching case independant set the filteroptions-caseinsensitive to true You can do combination filters eg Table1.Filter:='Name='van der*' and Surname='k*'; or you can even do nested combinations eg Table1.Filter:='(Name='van der*' and Surname='k*')or number=10'; Please note that is very basic and is not the recommended way to do things when you are on a Network it works only nice for local machines as it tends to create a lot of network traffic. The article is intended for first-timers