12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

448 Day 12<br />

Operator Use<br />

() Encloses <strong>in</strong>dividual elements of a compound expression<br />

[] Encloses field names with spaces<br />

AND, OR, NOT Jo<strong>in</strong>s <strong>in</strong>dividual elements of compound expressions<br />

You can also filter records us<strong>in</strong>g the OnFilterRecord event. OnFilterEvent looks like this:<br />

void __fastcall TForm1::Table1FilterRecord(TDataset *TDataset,<br />

Boolean &Accept)<br />

{<br />

Accept=(dlr==vhlead);<br />

}<br />

The OnFilterRecord event handler sets the value of the Accept parameter to <strong>in</strong>dicate whether<br />

a row meets the filter criteria. Note that the TDataset to which the filter corresponds is also<br />

passed <strong>in</strong> as a parameter. In the previous example, only those properties with gas heat are<br />

visible when the filter is active. Note the use of the Value variant property to set the Accept<br />

parameter.<br />

You can also use the F<strong>in</strong>dFirst, F<strong>in</strong>dNext, F<strong>in</strong>dPrior, and F<strong>in</strong>dLast methods to search an<br />

unfiltered TDataset us<strong>in</strong>g a filter expression. F<strong>in</strong>dFirst locates the first row match<strong>in</strong>g the<br />

filter expression; F<strong>in</strong>dNext locates the next one that does. F<strong>in</strong>dPrior locates the previous row<br />

match<strong>in</strong>g the filter expression, and F<strong>in</strong>dLast locates the last one that does.<br />

FilterOptions is a set variable that can <strong>in</strong>clude two possible elements:<br />

Element Mean<strong>in</strong>g<br />

foCaseInsensitive The filter ignores the case of the TDataset’s data<br />

foNoPartialCompare Partial field matches aren’t allowed<br />

You can set them us<strong>in</strong>g <strong>C++</strong>Builder’s Object Inspector.<br />

Ranges<br />

The SetRangeStart, SetRangeEnd, EditRangeStart, EditRangeEnd, ApplyRange, and SetRange<br />

methods also allow you to limit the set of rows visible to your application. Unlike<br />

<strong>C++</strong>Builder’s more flexible local filters, the rows with<strong>in</strong> the set must correspond to a<br />

consecutive set of keys with<strong>in</strong> an <strong>in</strong>dex when you’re deal<strong>in</strong>g with local tables. For SQL tables,<br />

the fields can be any listed <strong>in</strong> the IndexFieldNames property. The CancelRange method makes<br />

all rows aga<strong>in</strong> visible to your application.<br />

Locate/Lookup<br />

The Locate and Lookup methods allow you to search for rows <strong>in</strong> a table. They’re much more<br />

flexible than the F<strong>in</strong>dKey/SetKey family of functions because they do not require the use of an<br />

<strong>in</strong>dex and can therefore be used with Query and StoredProc components <strong>in</strong> addition to Table<br />

components. You choose the data you want, and the BDE f<strong>in</strong>ds the best way to access it.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!