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.

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

Table 12.20. TDataSource key methods.<br />

Method Function<br />

Edit Switches the associated TDataset <strong>in</strong>to Edit mode.<br />

Table 12.21. TDataSource key events.<br />

Event Catalyst<br />

OnDataChange Occurs when data is changed or the record po<strong>in</strong>ter moves.<br />

OnStateChange Occurs when the State property changes.<br />

OnUpdateData Occurs when Post or UpdateRecord is called.<br />

Key Elements<br />

The TDataset property identifies the TTable, TQuery, or TStoredProc that supplies the<br />

component with data. The AutoEdit property determ<strong>in</strong>es whether modify<strong>in</strong>g the contents<br />

of a data-aware control will automatically switch the TDataset <strong>in</strong>to Edit mode, allow<strong>in</strong>g<br />

changes to be made to the underly<strong>in</strong>g data.<br />

Tasks<br />

You can monitor changes to a TDataset and its associated data-aware controls by assign<strong>in</strong>g<br />

an event handler to the OnDataChange event.<br />

The OnStateChange event occurs when the State of the TDataset changes. For example, if you<br />

switch the TDataset’s State from dsBrowse to dsEdit by call<strong>in</strong>g the Edit rout<strong>in</strong>e, this event<br />

will be triggered. Because OnStateChange can occur for nil TDatasets, be sure to check for a<br />

nil TDataset before attempt<strong>in</strong>g to reference it.<br />

If you want to change the data <strong>in</strong> the current row before it is posted, set up an OnUpdateData<br />

event. It’s triggered when Post or UpdateRecord is called.<br />

TUpdateSQL<br />

Module: DBTables Class ancestor: TDataSetUpdateObject<br />

The TUpdateSQL component enables you to control the way that TDatasets are updated.<br />

Because you have complete control over the update process, you can even update read-only<br />

TDatasets. You do this via TUpdateSQL’s InsertSQL, DeleteSQL, and ModifySQL properties,<br />

which allow you to specify the SQL to execute for row <strong>in</strong>sertions, deletions, and updates.<br />

465<br />

12

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

Saved successfully!

Ooh no, something went wrong!