Why xBrowse displays all fields ?

Re: Why xBrowse displays all fields ?

Postby nageswaragunupudi » Sun Jan 30, 2011 3:17 pm

Parametrized Browse function - How to proceed?

XBrowse has too many settings and all of them can be handled through parameters to a function. If we try to, the function may be too clumsy. Instead use most commonly varying variables as parameters and rest of them through a call back codeblock.

In any case, the most important parameters are the column specifications. They are (1) Column name or an expression or codeblock, (2) Header, (3) Picture (4) Width, (5) Sort order and (6) Alignment. There are quite a few other specifications for the columns, which we can handle through call back codeblock.

In most cases, we do not need to specify all the specifications for the columns. When we speicify column name, XBrowse itself decides all other specifications which in most cases are suitable or even better than what we may specify. But there are cases like when we speicify expressions or codeblocks we need to provide other specifications too.

I suggest making a multi-dimensional array of all the specifications that are necessary. Such an array makes the specifications clear to understand and easier to maintain. Also we may notice later that the same specification would apply without any change for RDD, RecordSets and TDatabase classes. Example you can see in the program given below.

I have chosen the CUSTOMER.DBF in the \fwh\samples folder for this purpose.
Code: Select all  Expand view
#include "FiveWin.Ch"
#include "ord.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//

function Main()

   local aCols

   USE CUSTOMER NEW ALIAS CUST SHARED

/*
*  Set up all info for the all the columns in this multi-dimentional array
*  Each row contains parameters for each column
*  Each row or array can contain 1 to 6 columns ( elements )
*  Columns 2 to 6 are optional
*  Col 1:  Column name or Expression or CodeBlock
*  Col 2:  Header
*  Col 3:  Picture
*  Col 4:  Column width in pixels
*  col 5:  Sort Order
*  Col 6:  Alignment
*
*  Specify what are essential. Better we leave as much as possible to defults of xbrowse
*/




   aCols := { ;
   { "PADR( FIRST - ( '-' + LAST ), 60 )", "Customer Name", , 200 }, ;
   { "City" }, ;
   { "(DATE()-HIREDATE)/365", "Service", "999" }, ;
   { "Salary" } ;
   }

   MyXBrowse( nil, nil, "My Title", "CUST", aCols, nil ) // see below for syntax

return (0)

//----------------------------------------------------------------------------//

init procedure PrgInit

    SET DATE ITALIAN
    SET CENTURY ON
    SET TIME FORMAT TO "HH:MM:SS"
    SET EPOCH TO YEAR(DATE())-50

    SET DELETED ON
    SET EXCLUSIVE OFF

    RDDSETDEFAULT( "DBFCDX" )

    XbrNumFormat( 'I', .t. )
    SetGetColorFocus()

return

//----------------------------------------------------------------------------//

function MyXBrowse( oWnd, aRect, cTitle, uData, aCols, bSetUp )

   local oBrw
   local lOwnWnd  := .f.

   DEFAULT aRect  := { 0, 0, 0, 0 }, ;
           cTitle := "XBROWSE", ;
           uData  := Alias()

   aCols          := ASize( ArrTranspose( aCols ), 6 )

   if oWnd == nil
      DEFINE WINDOW oWnd TITLE cTitle
      lOwnWnd     := .t.
   endif

   @ aRect[ 1 ], aRect[ 2 ] XBROWSE oBrw SIZE aRect[ 3 ], aRect[ 4 ] PIXEL OF oWnd ;
      COLUMNS aCols[ 1 ] HEADERS aCols[ 2 ] PICTURES aCols[ 3 ] ;
      COLSIZES aCols[ 4 ] SORT aCols[ 5 ] JUSTIFY aCols[ 6 ] ;
      AUTOSORT DATASOURCE uData ;
      CELL LINES

   if bSetUp != nil
      Eval( bSetUp, oBrw )
   endif

   if lOwnWnd
      oBrw:CreateFromCode()
      if aRect[ 1 ] == 0 .and. aRect[ 2 ] == 0 .and. aRect[ 3 ] == 0 .and. aRect[ 4 ] == 0
         oWnd:oClient   := oBrw
      endif
      ACTIVATE WINDOW oWnd MAXIMIZED
   endif

return oBrw

 

Please compile and test this program in the \fwh\samples folder.

I see that there is a prevalent opinion that it is not possible to make a paramtertrized xbrowse function without using the syntax like oBrw:AddCol() and some programmers have even argued with me. The above sample proves that this opinion is not correct. And I still maintain that approach is not the way to get the best out of xbrowse.

This function could be the starting point for development of your own custom parametrized function. After you test we can discuss how to proceed further to implement it for your taste and needs.
Regards

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

Re: Why xBrowse displays all fields ?

Postby HunterEC » Mon Jan 31, 2011 7:01 am

Rao:

Thank you very much. Very kind on your part. I'll test it and give you my feedback. For now, what the ArrTranspose function does ? I can't find it in the FWH manual

I'm getting a compiler error:
Code: Select all  Expand view
Compiling...
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6717)
Copyright 1999-2010, http://www.xharbour.org http://www.harbour-project.org/
Compiling 'GENXBROW.prg' and generating preprocessed output to 'GENXBROW.ppo'...

GENXBROW.prg(84) Error E0030  Syntax error: "syntax error at '{'"
1 error
 


I'm using FiveWin 10.06

Best regards,

Gustavo
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: Why xBrowse displays all fields ?

Postby nageswaragunupudi » Mon Jan 31, 2011 9:09 am

1) Please change DATASOURCE as ALIAS in the @ ... XBROWSE command.

This should solve syntax error problem.

2) ArrTranspose( aArray ) --> aTransposeedArray is a function available in FWH. I am not sure if that function was available in 10.06. In case you get linking error that this function is not available, please let me know.
Regards

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

Re: Why xBrowse displays all fields ?

Postby anserkk » Mon Jan 31, 2011 11:00 am

nageswaragunupudi wrote:2) ArrTranspose( aArray ) --> aTransposeedArray is a function available in FWH. I am not sure if that function was available in 10.06.


Function ArrTranspose( aArray ) is availabe from FWH 10.8 onwads

Regards
Anser
User avatar
anserkk
 
Posts: 1331
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Why xBrowse displays all fields ?

Postby HunterEC » Mon Jan 31, 2011 1:43 pm

Rao:

ArrTranspose gave me linking errors. Thank you.

Gustavo
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 113 guests