ADD COLUMN TO XBROWSE

ADD COLUMN TO XBROWSE

Postby devtuxtla » Mon Mar 20, 2017 10:42 pm

Hi Nages.

I need your help to convert this funtion into xbrowse, this work well with Tsbrowse

FUNCTION N21A_DEFCOLUMN(_oBR, D_COLUMNAS)
LOCAL X:=0, _PIC, _COLOR:=""
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 BROWSE _oBR ;
DATA ( N21A_FieldSetGetBlock( "ST", x ) ) ;
HEADER D_COLUMNAS[X,1] SIZE (D_COLSIZES[X]) ;
COLOR CLR_BLACK , _NCOLOR ;
PICTURE _PIC ;
EDITABLE
NEXT


Thank for your help

Regards
Visite Chiapas, el paraiso de México.
devtuxtla
 
Posts: 392
Joined: Tue Jul 29, 2008 1:55 pm

Re: ADD COLUMN TO XBROWSE

Postby nageswaragunupudi » Tue Mar 21, 2017 11:48 am

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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10245
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: ADD COLUMN TO XBROWSE

Postby devtuxtla » Wed Mar 22, 2017 7:24 pm

Hi Nages

I congratulate you that xbrowse is a very good tool.

I'm in the process of migrating our application from xHarbour to Harbor.

The reason that the routine generates a browse as well as it sends, it is due that the user uses a data dictionary to order the columns of the table as it requires, so we can not show the table in the order of the DBSTRUCT() fields .

Each user of the system orders the information in the way that it requires and also adds a color to the column ...

We can not change that system behavior.

It is excellent that xBrowse with a single line, show the contents of the table.

We will use the two methods you suggest.

Thank you
Visite Chiapas, el paraiso de México.
devtuxtla
 
Posts: 392
Joined: Tue Jul 29, 2008 1:55 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 12 guests