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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>C++</strong>Builder Database Architecture<br />

Locate<br />

The Locate method takes three parameters: a str<strong>in</strong>g that identifies the field(s) you want to<br />

search, a variant that lists the values to search for, and a TLocateOptions set variable that<br />

specifies options for the search. Here’s the syntax for the Locate function:<br />

System::Boolean __fastcall Locate(const System::AnsiStr<strong>in</strong>g KeyFields,<br />

const System::Variant &KeyValues, TlocateOptions Options);<br />

You separate multiple field names with semicolons <strong>in</strong> Locate’s KeyFields parameter and pass<br />

their values as a variant array <strong>in</strong> its KeyValues parameter. Locate’s Options parameter is of type<br />

TLocateOptions and enables you to specify options that control the search. The parameter is<br />

a set variable and can have two possible values, loCaseInsensitive and loPartialKey. The<br />

first option, loCaseInsensitive, tells Locate to perform a search that is not case sensitive. The<br />

second one, loPartialKey, allows for partial key searches. You can pass either one or both of<br />

these by assign<strong>in</strong>g them to a set variable like so:<br />

TLocateOptions SearchOpts<br />

SearchOpts Locate(“NAME”,”Cri”,SearchOpts);<br />

Locate uses the fastest available means of satisfy<strong>in</strong>g your search criteria. If an <strong>in</strong>dex exists that<br />

can satisfy the search request, Locate uses it. If an <strong>in</strong>dex does not exist that can service the<br />

search, a BDE filter is constructed. Either way, the fastest possible path to your data is taken.<br />

Locate returns true if it’s able to locate the data you request, and false if it isn’t.<br />

Lookup<br />

Similarly to the Locate function, the Lookup function takes three parameters: a str<strong>in</strong>g<br />

parameter specify<strong>in</strong>g a semicolon-delimited list of columns to search for, a variant or variant<br />

array specify<strong>in</strong>g the column values to search for, and a str<strong>in</strong>g parameter list<strong>in</strong>g the names of<br />

columns to return <strong>in</strong> the function’s result. Here’s the syntax for the Lookup function:<br />

System::Boolean __fastcall Lookup(const System::AnsiStr<strong>in</strong>g KeyFields,<br />

const System::Variant &KeyValues,const System::AnsiStr<strong>in</strong>g ResultFields);<br />

In addition to perform<strong>in</strong>g a TDataset search, Lookup returns values from the operation as well.<br />

If a match<strong>in</strong>g row cannot be found, Lookup returns a null variant. If a match<strong>in</strong>g row is found,<br />

Lookup first processes any lookup fields you’ve def<strong>in</strong>ed for its associated TDataset, and then<br />

returns the values of the fields you’ve specified <strong>in</strong> ResultColumns. If ResultColumns lists<br />

multiple fields, the result is a variant array; otherwise, it’s just a simple variant.<br />

Cached Updates<br />

<strong>C++</strong>Builder’s cached updates mechanism enables you to delay apply<strong>in</strong>g updates to your<br />

database back end. You can decide when to apply updates, and then apply them all at once.<br />

Normally, updates are applied as soon as you make them. For client/server applications, this<br />

449<br />

12

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

Saved successfully!

Ooh no, something went wrong!