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.

446 Day 12<br />

Note that you can double-click MasterFields to <strong>in</strong>voke <strong>C++</strong>Builder’s Field L<strong>in</strong>k Designer,<br />

which enables you to establish master/detail relationships visually.<br />

Sett<strong>in</strong>g the Active property to true is identical to call<strong>in</strong>g the TDataset’s Open method—it<br />

opens the TDataset. Likewise, sett<strong>in</strong>g Active to false is the same as call<strong>in</strong>g the TDataset’s<br />

Close method—it closes the TDataset.<br />

You can check the current status of a TDataset with the State property. It will have one of<br />

the follow<strong>in</strong>g values:<br />

■ dsInactive—The TDataset is closed.<br />

■ dsBrowse—The TDataset is <strong>in</strong> Browse mode. The TDataset can be navigated, but<br />

changes can’t be made to the data until State is switched to dsEdit.<br />

■ dsEdit—The TDataset is <strong>in</strong> EUdit mode and allows changes to the data.<br />

■ dsInsert—The TDataset is <strong>in</strong> Insert mode.<br />

■ dsSetKey—The TDataset is <strong>in</strong> SetKey mode because SetKey has just been called.<br />

When values are assigned to columns while <strong>in</strong> this mode, they are <strong>in</strong>terpreted as<br />

search values. A subsequent GotoKey will search for a record us<strong>in</strong>g these values.<br />

■ dsCalcFields—The OnCalcFields event handler is be<strong>in</strong>g called.<br />

Tasks<br />

The First method moves the current record po<strong>in</strong>ter (also known as the cursor) to the top<br />

of the TDataset, and the Last method moves to the bottom. The Prior and Next methods<br />

move to the previous and next rows, respectively. Use the MoveBy method to move a number<br />

of rows forward or backward from the current row.<br />

The SetKey, F<strong>in</strong>dKey, GotoKey, F<strong>in</strong>dNearest, and GotoNearest methods can be used to search<br />

the TDataset for a given set of field values.<br />

You use the Bof property to determ<strong>in</strong>e whether the TDataset cursor is at its beg<strong>in</strong>n<strong>in</strong>g. You<br />

use the Eof property to determ<strong>in</strong>e whether the cursor has reached the TDataset’s end. These<br />

two properties can be useful <strong>in</strong> loop<strong>in</strong>g through the rows <strong>in</strong> a TDataset. For example, here’s<br />

a simple rout<strong>in</strong>e that loops through a table’s rows, display<strong>in</strong>g a field from each as it goes:<br />

Table1->First();<br />

while (!(Table1->Eof)) {<br />

ShowMessage(“Category is: “+Table1->FieldByName(“Category”)->Value);<br />

Table1->Next();<br />

}

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

Saved successfully!

Ooh no, something went wrong!