#include "fivewin.ch"
// ------------------------------------------------------------------------ //
FUNCTION main
LOCAL oWnd,oBrw,oCol
LOCAL aEmploy
SET DATE BRITISH
SET CENTURY ON
DEFINE WINDOW oWnd FROM 0,0 TO 480,640 PIXEL
oWnd:center()
// create a dummy browse
@ 0,0 LISTBOX oBrw FIELDS "" HEADERS "" COLSIZES 10 SIZE 630,470 PIXEL OF oWnd
SET MENU OF oWnd TO MainMenu(oWnd,oBrw)
ACTIVATE WINDOW oWnd
RETURN NIL
// ------------------------------------------------------------------------ //
FUNCTION mainmenu(oWnd,oBrw)
LOCAL oMenu
MENU oMenu
MENUITEM "&File"
MENU
MENUITEM "Refresh Browse &1" ACTION Refresh1(oBrw)
MENUITEM "Refresh Browse &2" ACTION Refresh2(oBrw)
SEPARATOR
MENUITEM "E&xit" ACTION oWnd:end()
ENDMENU
ENDMENU
RETURN oMenu
// ------------------------------------------------------------------------ //
FUNCTION Refresh1(oBrw)
// { { cName, cJobTitle, lIsFullTime, nAge, dJoinedFirm }, ... }
LOCAL aArrayData := { { "Smith", "Sales Executive", .T., 40, CToD("16/06/2000") }, ;
{ "Jones", "Sales Assistant", .F., 25, CToD("21/10/2009") }, ;
{ "Brown", "Head of Research & Development", .T., 45, CToD("12/10/2001") } }
oBrw:SetArray(aArrayData)
oBrw:bLine := { |o| DispVals(aArrayData,o) }
oBrw:aHeaders := { "Name","Job Title","Fultime?","Age","Date joined firm" } // MUST have the same number of elements as value returned by :bLine
oBrw:aColSizes := { 150, 150, 30, 150, 150 } // MUST be specified here otherwise program falls over!!!
oBrw:aJustify := { .F., .F., .F., .T., .F. }
oBrw:refresh()
RETURN NIL
// ------------------------------------------------------------------------ //
FUNCTION Refresh2(oBrw)
// { { cName, nAge, dJoinedFirm }, ... }
LOCAL aArrayData := { { "Smith", 40, CToD("16/06/2000") }, ;
{ "Jones", 25, CToD("21/10/2009") }, ;
{ "Brown", 45, CToD("12/10/2001") } }
oBrw:SetArray(aArrayData)
oBrw:bLine := { |o| DispVals(aArrayData,o) }
oBrw:aHeaders := { "Name","Age","Date joined firm" } // MUST have the same number of elements as value returned by :bLine
oBrw:aColSizes := { 210, 210, 210 } // MUST be specified here otherwise program falls over!!!
oBrw:aJustify := { .F., .T., .F. }
oBrw:refresh()
RETURN NIL
******************************************************************************
* DispVals(): returns an array with the current row of browse converted to
* character values
******************************************************************************
STATIC FUNCTION DispVals(aArrayData,oBrw)
LOCAL aDisplay
LOCAL nRowCount := oBrw:nAt, ;
nColCount, nColMax
nColMax := len(aArrayData[1])
aDisplay := array(nColMax)
FOR nColCount := 1 TO nColMax
aDisplay[nColCount] := cValToChar(aArrayData[nRowCount][nColCount]) // convert to character datatype
NEXT
RETURN aDisplay