TArrayData

Fuente: source/classes/tarrdata.prg

TArrayData provides a uniform data source interface over Harbour arrays, DBF tables, and MariaDB/MySQL queries. It acts as a bridge between data and XBrowse, allowing any data source to be browsed, sorted, filtered, and edited using the same API. Internally, data is stored as an array of row arrays with a matching field structure definition.

Key DATA Members

DATATypeDescription
aDataArrayArray of row arrays containing all data
aStructArrayField structure array (compatible with DbStruct())
nAtNumericCurrent row position (1-based)
nSrcTypeNumericSource type: SRC_ARR (0), SRC_DBF (1), SRC_MYQ (2)
nOrderNumericCurrent sort column position
lDescLogicalDescending sort order flag
lReadOnlyLogicalRead-only mode
cFilterCharacterActive filter expression
bFilterBlockFilter code block
lFoundLogicalResult of last Seek operation
bEditBlockCode block for record editing
bKeyCountBlockCode block returning record count
cAliasCharacterAlias name (default "ARRAY")

Constructors

MethodDescription
New( aData, aStruct )Create from array and structure definition
fromDBF( cAlias, bFor, bWhile, nNext, nRec, lRest )Load data from DBF with optional filter
fromMYSQL( oCn, cTable, cWhere )Load data from MariaDB/MySQL table
fromQuery( oCn, cSql, aParams )Load from SQL query result
fromFIELD( cAlias, aStruct, cField )Load from a memo field containing array data

Methods

MethodDescription
FieldGet( n )Get field value by position from current row
FieldPut( nFld, uValue )Set field value in current row
FieldPos( cFld )Get field position by name
FieldName( n )Get field name by position
FieldType( n )Get field type by position
FieldLen( n )Get field length by position
FieldDec( n )Get field decimals by position
FieldPic( n, c )Get/set field picture format
FCount()Number of fields
GoTop() / GoBottom() / Skip( n )Navigate within data
RecNo() / GoTo( nRecNo )Position by record number
KeyNo() / KeyGoTo( nKeyNo )Absolute position (1-based)
RecCount() / LastRec()Total number of records
Bof() / Eof()Boundary checks
Seek( uVal, lSoft, lWild )Search for value in current sort column
SetOrder( cCol, u, lDescend )Set sort column and direction
SetFilter( cFilter )Set filter expression
Append( aRow, nAt )Append a new row
Delete()Delete current record
SetXBrowse( oBrw, aCols, lAutoSort, lAutoCols )Bind to XBrowse with automatic column definition
Record( cFieldList, lNew )Get a TDataRow for editing
Edit()Edit current record via TDataRow
SaveData()Save data back to source (DBF or MySQL)

Example: Array to XBrowse with Sort

#include "FiveWin.ch"

function Main()

   local aData, aStruct, oWnd, oBrw

   // Define structure
   aStruct := { { "NAME", "C", 20, 0 }, ;
                { "AGE",  "N",  3, 0 }, ;
                { "CITY", "C", 15, 0 } }

   // Sample data
   aData := { { "Alice",   30, "New York" }, ;
              { "Bob",     25, "Boston"   }, ;
              { "Charlie", 35, "Chicago"  } }

   DEFINE WINDOW oWnd TITLE "Array Data Browser" SIZE 500, 300

   @ 0, 0 XBROWSE oBrw OF oWnd AUTOSORT
   oBrw:SetArrayData( aData, aStruct )
   oBrw:CreateFromCode()

   ACTIVATE WINDOW oWnd CENTERED

return nil

Notes

Ver También