Here is a small sample. Two calculated columns are created with a simple syntax like :
- Code: Select all Expand view
- oBrw:DueDate := { || oBrw:Date:Value + oBrw:Credit:Value }
oBrw:Interest := { || Max( Date() - oBrw:DueDate:Value, 0 ) * oBrw:Advance:Value * 0.1 }
This code is easy to write and easy to understand and maintain. This code has an additional benefit of being portable across different sources of data ( RDD, Array, RecordSet, etc ).
Sample code:
- Code: Select all Expand view
- #include 'fivewin.ch'
#include 'xbrowse.ch'
function Main()
local oDlg, oBrw, oFont
local aData
SET DATE ITALIAN
SET CENTURY ON
aData := CreateRandomData()
DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12
DEFINE DIALOG oDlg SIZE 500,400 PIXEL FONT oFont ;
TITLE 'XBrwose Calculated Columns'
@ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
AUTOCOLS ARRAY aData ;
HEADERS 'Date', 'Advance', 'Credit' ;
PICTURES nil, '9,999,999.99', '99 Days' ;
CELL LINES NOBORDER FASTEDIT
AEval( oBrw:aCols, { |o| o:nEditType := EDIT_GET } )
// Now add calculated columns
oBrw:DueDate := { || oBrw:Date:Value + oBrw:Credit:Value }
oBrw:Interest := { || Max( Date() - oBrw:DueDate:Value, 0 ) * oBrw:Advance:Value * 0.1 }
// end of Calculated columns
oBrw:DueDate:bClrStd := { || { If( oBrw:DueDate:Value < Date(), CLR_HRED, CLR_BLACK ), CLR_WHITE } }
oBrw:Interest:cEditPicture := '@Z 9,999,999.99'
oBrw:nStretchCol := 2
oBrw:CreateFromCode()
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
static function CreateRandomData()
local aData := {}
local n
for n := 1 to 50
AAdd( aData, ;
{ Date() - HB_RandomInt( 90 ), ;
Round( HB_Random( 5000, 25000 ), 2 ), ;
HB_RandomInt( 1, 3 ) * 15 } )
next n
return aData
ScreenShot:
First three columns can be edited and the calculated columns ( DUEDATE and INTEREST) are recalculated and refreshed automatically.