This is the modified program with your function that works with XBrowse, following your style of programming.
- Code: Select all Expand view
#include "fivewin.ch"
function Main()
local oWnd, oBrw
USE CUSTOMER NEW ALIAS "ST" VIA "DBFCDX"
DEFINE WINDOW oWnd
@ 0,0 XBROWSE oBrw SIZE 0,0 PIXEL OF oWnd DATASOURCE "ST" LINES NOBORDER
N21A_DEFCOLUMN( oBrw, ST->( DBSTRUCT() ) )
oBrw:CreateFromCode()
ACTIVATE WINDOW ownd MAXIMIZED
return nil
FUNCTION N21A_DEFCOLUMN(_oBR, D_COLUMNAS)
LOCAL X:=0, _PIC, _COLOR:=""
LOCAL _NCOLOR
LOCAL D_COLSIZES := {}
PRIVATE NCOLOR1 := CLR_WHITE, NCOLOR2 := CLR_HGRAY, NCOLOR3 := CLR_GRAY
PRIVATE NCOLOR4 := CLR_YELLOW, NCOLOR5 := CLR_WHITE, NCOLOR6 := CLR_HGRAY
PRIVATE NCOLOR7 := CLR_WHITE, NCOLOR8 := CLR_HGRAY, NCOLOR9 := CLR_GRAY
D_COLSIZES:={}
FOR X = 1 TO LEN(D_COLUMNAS)
AADD(D_COLSIZES, IIF(D_COLUMNAS[X,3] < 3 , 40 , D_COLUMNAS[X,3] * 9 ) )
_NCOLOR:= "NCOLOR" + ALLTRIM(IIF(X < 10, STR(X), "2"))
_NCOLOR:= &_NCOLOR
_PIC := IIF(D_COLUMNAS[X,2] = "N", REPLICATE("9",D_COLUMNAS[X,3]) + ".9999", REPLICATE("!",D_COLUMNAS[X,3]) )
ADD COLUMN TO XBROWSE _oBR ;
DATA FIELDWBLOCK( D_COLUMNAS[ x, 1 ], SELECT( "ST" ) ) ; //( N21A_FieldSetGetBlock( "ST", x ) ) ;
HEADER D_COLUMNAS[X,1] SIZE (D_COLSIZES[X]) ;
COLOR CLR_BLACK , _NCOLOR ;
PICTURE _PIC ;
EDITABLE
NEXT
return nil
But all this kind of lengthy code is not necessary for using XBrowse. Not only unnecessary, but also not desirable and nor recommended.
What all you wanted to do, excepting the colors can be done using this short code.
- Code: Select all Expand view
#include "fivewin.ch"
function Main()
local oWnd, oBrw
USE CUSTOMER NEW ALIAS "ST" VIA "DBFCDX"
DEFINE WINDOW oWnd
@ 0,0 XBROWSE oBrw SIZE 0,0 PIXEL OF oWnd DATASOURCE "ST" AUTOCOLS LINES NOBORDER
AEval( oBrw:aCols, { |o| If( o:cDataType == 'C', o:cEditPicture := "@!", nil ) }
oBrw:CreateFromCode()
ACTIVATE WINDOW ownd MAXIMIZED
return nil
Clause AUTOCOLS is used for all columns. If we want only specified columns, then we should
- Code: Select all Expand view
@ 0,0 XBROWSE oBrw SIZE 0,0 PIXEL OF oWnd DATASOURCE "ST" ;
COLUMNS "First", "City", "Age", "Salary" ;
LINES NOBORDER
We recommend specifying column names ( even complex expressions ) as strings and not as codeblocks. This way XBrowse knows what columns of which DBF we are showing. From this information XBrowse examines the DBSTRUCT() of the alias and determines:
a) Column size depending on FIELDLEN()
b) Alignment depending on FIELDTYPE()
c) Picture clause depending on FIELDTYE(), FIELDLEN() and FIELDDEC() and also depending on the Global setting in FWNumformat(). XBrowse determines the thousands separator and country based formatting based on FWNumFormat() settings.
(d) XBrowe decides the GETSET codeblock in such a way that it is possbile to substitute a different alias at runtime.
(e) XBrowse also decides how and when to Lock() and Unlock() for writing data.
(f) Examines all open indexes and determine what index tag (order) should be used for which column to autosorting and incremental seeks,etc.
(g) And a lot more.
Adopting the old style of programming used with other browses is the surest way to deny all the power of xbrowse and use it as any other dumb browse. In a nutshell it is good not to spoon-feed XBrowse.
It is possible that you may need more clarifications. Please feel free to ask.