Sample:
/*
* tstdrow.prg
* test TDataRow usage
*
*/
#include "fivewin.ch"
#include "xbrowse.ch"
#include "adodef.ch"
REQUEST DBFCDX
//----------------------------------------------------------------------------//
function Main()
聽 聽local uDataSource
聽 聽SET DATE ITALIAN
聽 聽SET CENTURY ON
聽 聽SET DELETED ON
聽 聽FWNumFormat( "A", .t. )
聽 聽uDataSource := OpenData()
聽 聽BrowseData( uDataSource )
聽 聽CloseData( 聽uDataSource )
return nil
//----------------------------------------------------------------------------//
// TESTING XBROWSE WITH TDATAROW
// Both XBrowse and TDataRow Code is the same for all Data Sources
//----------------------------------------------------------------------------//
static function BrowseData( uData )
聽 聽local oDlg, oBrw, oFont, oRec
聽 聽DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
聽 聽DEFINE DIALOG oDlg SIZE GetSysMetrics(0) * 0.9,400 PIXEL FONT oFont ;
聽 聽 聽 TITLE "TDataRow test : " + FWVERSION
聽 聽@ 30,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
聽 聽 聽 DATASOURCE uData AUTOCOLS AUTOSORT ;
聽 聽 聽 FOOTERS CELL LINES NOBORDER
聽 聽WITH OBJECT oBrw
聽 聽 聽 :nEditTypes 聽 聽:= EDIT_GET
聽 聽 聽 :Married:SetCheck()
聽 聽 聽 //
聽 聽 聽 :CreateFromCode()
聽 聽END
聽 聽@ 10, 10 BUTTON "Edit" SIZE 40,12 PIXEL OF oDlg ;
聽 聽 聽 ACTION ( oRec := TDataRow():New( uData ), oRec:Edit(), oBrw:Refresh(), oBrw:SetFocus() )
聽 聽@ 10, 60 BUTTON "Append" SIZE 40,12 PIXEL OF oDlg ;
聽 聽 聽 ACTION ( oRec := TDataRow():New( uData, nil, .t. ), oRec:Edit(), oBrw:Refresh(), oBrw:SetFocus() )
聽 聽@ 10,110 BUTTON "Delete" SIZE 40,12 PIXEL OF oDlg ACTION ( oBrw:Delete(), oBrw:SetFocus() )
聽 聽ACTIVATE DIALOG oDlg CENTERED
聽 聽RELEASE FONT oFont
return nil
//----------------------------------------------------------------------------//
static function OpenData()
聽 聽local nChoice, uDataSource
聽 聽nChoice := Alert( "Choose DataSource", { "DBF", "TDATABASE", "ADO", "Quit" }, "DATASOURCE" )
聽 聽if nChoice 聽<= 2
聽 聽 聽 USE C:\FWH\SAMPLES\CUSTOMER NEW ALIAS CUST SHARED VIA "DBFCDX"
聽 聽 聽 if nChoice == 1
聽 聽 聽 聽 聽uDataSource 聽 聽:= Alias()
聽 聽 聽 else
聽 聽 聽 聽 聽DATABASE uDataSource
聽 聽 聽 endif
聽 聽elseif nChoice == 3
聽 聽 聽 uDataSource := FW_OpenRecordSet( "c:\fwh\samples\xbrtest.mdb", "CUSTOMER" )
聽 聽else
聽 聽 聽 QUIT
聽 聽endif
return uDataSource
//----------------------------------------------------------------------------//
static function CloseData( uDataSource )
聽 聽if ValType( uDataSource ) == 'C'
聽 聽 聽 ( uDataSource )->( DbCloseArea() )
聽 聽elseif ValType( uDataSource ) == 'O'
聽 聽 聽 uDataSource:Close()
聽 聽 聽 if uDataSource:ClassName() == "TOLEAUTO"
聽 聽 聽 聽 聽uDataSource:ActiveConnection:Close()
聽 聽 聽 endif
聽 聽endif
return nil
//----------------------------------------------------------------------------//
Please use latest FWH release.
The entire code to browse, add, edit and delete() work independently of the datasource. The same code works for RDD, TDatabase and ADO
This sample also demonstrates the latest feature oBrw:Delete().
New Delete() method of XBrowse deletes the current row in a manner appropriate to the datasource, repositions the current row and refreshes the browse.
In the above sample, I used the default Edit() of the TDataRow. Obviously we use custom edit dialog to edit/add the records. We can do this in to ways.
oRec := TDataRow():New( Source )
oRec:bEdit := { |oRec| MyEditDlg( oRec ) }
oRec:Edit()
Or
oRec := TDataRow():New( Source )
MyEditDlg( oRec )
Whichever way we edit, please use only built in UnDo() and Save() methods of TDataRow.