# Filter console A console program that goes deeper into `TAtlasDataFilter`, `TAtlasFilterEdit`, `TAtlasDBGrid.ExportCSV` and `TAtlasDBLookupCombo`, using a six-row FireDAC `TFDMemTable` of customers and a three-row table of categories. It checks, in order: 1. contains, prefix and exact matching, case-insensitive, with the record count after each `Apply`; 2. that the text match composes with the dataset's own `Filter` expression and with an existing `OnFilterRecord` handler, and that `Clear` restores both; 3. that a second filter cannot take over the dataset, that `Apply` refuses to run during an edit, and that an unknown field name keeps the previous filter; 4. that typing into a `TAtlasFilterEdit` applies the filter and clearing it removes the filter; 5. CSV export of the filtered, visible columns, of the selected rows only, to `customers.csv`, and the refusal to export while an edit is pending; 6. lookup selection by display text and by key, with the master record left in edit state and the lookup cursor left where it was. The controls are created on a form that is never shown; the data-aware controls need a parent window, not a visible one. Every step checks its own result. The program exits with code 0 when all checks pass, or prints the failed check and exits with code 1. It needs no input, database server or network. ## Build and run Open `FilterConsole.dpr` in Delphi 13; the IDE creates the project file. Add the Atlas Info `src` folder and the Atlas VCL `src` folder to the project's search path, then build and run for Win32 or Win64. No packages need to be installed. The program needs no input. It checks its own results and stops with an error if any of them differs from the output below. It writes `customers.csv` to the current directory. ## Expected output ``` 1. Text matching ok contains "ar" matches 4 of 6 names, case-insensitive ok Filter.Text holds the lower-cased text ok the filter is installed on the dataset ok prefix "a" matches Acorn Design and Anchor Marine ok exact match finds one record ok Clear shows every record again 2. Composing with an existing filter ok the native expression alone keeps 4 records ok text match AND native expression keeps 2 records ok Clear restores the native expression ok text match runs after the existing OnFilterRecord handler ok Clear restores the existing handler 3. Ownership and editing rules ok a second controller cannot take over the dataset ok Apply refuses to run while a record is being edited ok an unknown field keeps the previous filter 4. TAtlasFilterEdit drives the controller ok typing "ce" leaves Cedar Systems ok clearing the edit clears the filter 5. CSV export of the visible rows ok header plus the two filtered records ok hidden columns are left out of the header ok numbers and booleans use invariant text ok export restores the current record ok SelectedOnly exports the selected rows wrote ...\customers.csv ok export refuses pending edits instead of posting them 6. Lookup selection ok SelectText finds "Priority" from a prefix ok the master field changed, nothing was posted ok the lookup cursor did not move ok an unknown text returns False ok an unknown key raises and leaves the record alone ok SelectKey followed by Post stores the key PASS: 28 checks ``` `customers.csv` holds the two customers whose names start with "a", without the hidden `CategoryID` column: ``` ID,Name,Balance,Active 1,Acorn Design,1200.5,true 6,Anchor Marine,300,true ``` ## Adapting it Point `Filter.DataSet` at your own dataset and change the field names passed to `Apply`. To filter as the user types, keep the `TAtlasFilterEdit` part and drop the direct `Apply` calls. To export something other than the filtered rows, change which grid columns are visible before calling `ExportCSV`.