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
DATA Type Description
aDataArray Array of row arrays containing all data
aStructArray Field structure array (compatible with DbStruct())
nAtNumeric Current row position (1-based)
nSrcTypeNumeric Source type: SRC_ARR (0), SRC_DBF (1), SRC_MYQ (2)
nOrderNumeric Current sort column position
lDescLogical Descending sort order flag
lReadOnlyLogical Read-only mode
cFilterCharacter Active filter expression
bFilterBlock Filter code block
lFoundLogical Result of last Seek operation
bEditBlock Code block for record editing
bKeyCountBlock Code block returning record count
cAliasCharacter Alias name (default "ARRAY")
Constructors
Method Description
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
Method Description
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
TArrayData is the default data source used by XBrowse when oBrw:SetArrayData() is called. It is created internally by XBrowse from any data array.
When loaded from DBF, the data is a snapshot. Changes are not written back unless SaveData() is called, which updates the original DBF records.
The fromMYSQL() and fromQuery() constructors require a FWMariaConnection object and maintain a live link for writing back changes.
Sorting creates a sorted index internally; the original aData order is preserved in aNatural.
Ver También ← tanimate | tautoget →