TDataRow
Fonte: source/classes/datarow.prg
Standalone class
TDataRow is a data-record editor that provides a convenient interface for viewing and editing individual records from a data source. It works with DBF work areas, ADO recordsets, arrays, and hashes, making it a versatile tool for record-level operations. TDataRow maintains an original copy of the data and can detect modifications.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
aData | Array | Array of current field values |
aOrg | Array | Array of original field values (for change detection) |
aPrompts | Array | Array of field prompt/label strings |
uSource | Variant | Source data: alias (N), ADO recordset, array, or hash |
cSrcType | Character | Source type string: "DBF", "ADO", "ARR", or "HSH" |
bSave | Block | Code block evaluated on successful save |
bValid | Block | Code block for record validation before save |
bEdit | Block | Code block evaluated when edit begins |
Methods
| Method | Description |
|---|---|
New( uSource, cFieldList, lBlank, aInitVals ) | Create a data row from a source and optional field list |
Load( lBlank ) | Load current values from the source into aData |
Save( lCheck, lSilent ) | Write changes back to the source; optional validation |
Edit( lReadOnly, lNavigate, cTitle, cMsg ) | Open a dialog for interactive record editing |
Undo( fld ) | Revert a field to its original value |
Copy() | Create a copy of the current record data |
Paste( hRec ) | Paste a previously copied record into the buffer |
Modified( fld ) | Check if a field (or any field) has been modified |
FieldGet( fld ) | Get a field value by name or position |
FieldPut( fld, uVal ) | Set a field value by name or position |
Example: Edit Current DBF Record
#include "FiveWin.ch"
function Main()
local oDb, oRow
DATABASE oDb FILE "customers.dbf" DRIVER "DBFCDX" SHARED
oDb:GoTop()
// Create a data row for the current record
oRow := TDataRow():New( oDb:nArea )
// Open the edit dialog
if oRow:Edit( , , "Edit Customer" )
// User pressed OK -- changes are saved automatically
MsgInfo( "Record saved" )
else
MsgInfo( "Edit cancelled" )
endif
oDb:Close()
return nil
Notes
- TDataRow adapts to the source type automatically. For DBF sources, pass the work area number or alias; for ADO, pass the recordset object; for arrays or hashes, pass the reference directly.
- The
Edit()method creates a default dialog with TGet controls for each field. WhenlReadOnlyis .T., the dialog displays data without allowing edits. - Use
bSaveto execute custom logic after a successful save, such as logging or refreshing related controls. - The
Modified()method without arguments checks if any field changed; with a field argument it checks a specific field. - Using
lNavigate=.T.inEdit()adds navigation buttons (Next/Previous) to move between records.