All datas and methods of ADO RecordSet class can be used and is compatible with the existing code written using OleAuto RecordSet object.
This class also provides datas and methods similar to TDatabase, making it convenient to migrate from DBF to ADO by using TRecSet class in place of TDatabase class.
Purpose of this class are:
(1) To simplify coding with ADO recordsets to improve productivity.
(2) Provide familar methods like GoTop(), GoTo() etc for DBF users
(3) Ease migration from DBF to ADO for programmers who are already using TDatabase like classes.
Instantiation:
oRs := TRecSet():New()
oRs := TRecSet():New( oRs )
oRs := TRecSet():New( nil, source, actconn, cursortype, locktype, opt )Normal Usage, similar to the standard way:
oRs := TRecSet():New()
// Instead of oRs := TOleAuto():New( "ADODB.RecordSet" )
// Optionally set some data
WITH OBJECT oRs
  :Source = <...>
  <... etc ...>
END
oRs:Open( source,actconn,cursortyp,locktyp,opt ) // Exactly like ADO recordset
// All the code used with ADO Recordset works equally with the TRecSet objectWe can also open recordset in a single statement
oRs := TRecSet():New():Open( <params >For programs already written using standard RecordSet object opened with TOleAuto(), we can either
(a) Replace TOleAuto():New( "ADODB.RecordSet" ) with oRs := TRecSet():New()
OR
(b) oRs := TOleAuto():New( "ADODB.RecordSet )
oRs := TRecSet():New( oRs )
Using with already created RecordSet
oRs := oCn:OpenSchema( <id> )
oRs := TRecSet():New( oRs )
//[OR]
oRs := TRecSet():New( oCn:OpenSchema( <id> ) )In programs where FW_OpenRecordSet(...) is used for opening recordsets, please replace FW_OpenRecordSet(...) with FW_OpenTRecSet(...), retaining the same parameters.
Using compatible with TDataBase
oRs := TRecSet():New( nil, cTable, oConnection/cStr, cusortype, locktype, options )
if oRs:Used()
  // succcess
else
  // failure
endifWe can continue to use GoTop() etc methods same way as in TDatabase.
How does this class simplify some programming work:
We can refer to fields as datas same way as we do in TDatabase.
Eg:
? oRs:Age
oRs:Age += 5
oRs:Save()
We can also use familiar fieldget, etc.
oRs:FieldGet( "Salary" )
oRs:FieldPut( "Salary", 40000 )
While using field names containing blanks, we can replace blanks with underscore. Example:
Where a field name is "Sale Price",
? oRs:Sale_Price
? oRs:FieldGet( "Sale_Price" )
? oRs:FieldGet( "Sale Price" )
all the above can be used.
oRs:Fields( "Age" ):Value also works but the above code is a lot simpler.
In addition we can even use Expressions in FieldGet()
Example:
? oRs:FieldGet( "Quantity * Price" )
Using standard syntax we had to write
? oRs:Fields( "Quantity" ):Value * oRs:Fields( "Price" ):Value.
We are aware that we can not use some methods like oRs:MoveFirst(), etc on an empty recordset. This class simplifies this by doing the error checking and we can now use oRs:MoveFirst(), etc. without worrying about whether the recordset is empty or not.
We can also query the values of fields of an empty recordset. Now we can and the result is a blank value compatible to the field type.
We welcome users to try the class and offer suggestions for improvments and most importantly bug-reports are the most welcome. We endeavour to attend to any bug reports as immediately as possible.
G. N. Rao.
Hyderabad, India