1. Tech

Your suggestion is on its way!

An email with a link to:

http://delphi.about.com/od/database/l/aa061201a.htm

was emailed to:

Thanks for sharing About.com with others!

ADO Cursors
Page 1: How ADO uses cursors as a storage and access mechanism.
 More of this Feature
• Page 2: Cursor properties
 Join the Discussion
"Post your views and comments to this chapter of the free Delphi database Programming Course"
Discuss!
 Related Resources
• free DB Course.TOC
 Elsewhere on the Web
• Choosing and Managing Cursors

Welcome to the chapter ten of the free Delphi ADO Database Course for beginners. In the past nine chapters you were presented with some of the basic techniques when developing ADO-based Delphi applications. We've seen how several data-access components are used to connect and retrieve data from an Access database. One thing is for sure: ADOExpress components fit quite nicely into the Delphi data access model and map very closely to the basic data objects that ADO uses to access data.

However, the way you use ADOExpress components is quite different from the traditional Delphi programming with the BDE based TTable, and TQuery components. If you're accustomed to working with the BDE dataset components, there are a number of things you'll find different when you use ADO. The available properties are different, and so should be the programming style.

At the heart of ADO is the Recordset object. The Recordset object (aka Dataset) is a result of a Query command (SELECT statement of a TADOQuery component, for example). When an ADO-based application retrieves rows from a database, an ADO Recordset object encapsulates the data and the operations allowed on that data. ADO uses cursors to contain the logical set of rows maintained for a recordset. The cursor also provide the current position in the recordset. In development we use cursors to create a recordset to scroll forward or backward in, or to have the recordset pick up another user's changes.

   Cursor?!
The simplest definition would be: a query result set where browsing is enabled and the current position is known.

TADOTable.CursorType
Within ADO, cursors have three functions. First, the cursor type determines movement within the cursor and whether the recordset will reflect users changes. Second, the cursor location determines where to store the recordset while the cursor is open. Third, the cursor's locking type specifies how an ADO datastore will lock the rows when you want to make changes.

The understanding of cursors is extremely important. For example, in order to get our recordset to do the things we want, we need to open certain ADO recordsets with specific types of cursors. To RecordCount property, for example, is NOT supported with forward-only cursors.

In the ADOExpress set, TCustomADODataSet encapsulates a set of properties, events, and methods for working with data accessed through an ADO datastore. All the TCustomADODataSet descendant classes (TADODataSet, TADOTable, TADOQuery, and TADOStoredProc) share several common properties. Use the CursorType, CursorLocation, and LockType properties to create the most efficient recordset.

Next page > CursorType, CursorLocation, LockType > Page 1, 2

DB Course Next Chapter >>
>> Migrating from Paradox/dBase to Access with Delphi and ADO.

©2015 About.com. All rights reserved.