Why xBrowse displays all fields ?

Why xBrowse displays all fields ?

Postby HunterEC » Mon Jan 24, 2011 10:18 pm

Guys:
On the following code I can't find the problem that xBrowse shows all database fields instead of the ones that I defined:
Code: Select all  Expand view
       DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-14
       DEFINE DIALOG oDlg SIZE 637,600 PIXEL ;
          TITLE "Sample Records" ;
          FONT oFont

       @ 10,10 XBROWSE oBrw ;
          SIZE 300,230 PIXEL ;
          OF oDlg ;
          ALIAS "Sample" ;
          AUTOCOLS AUTOSORT LINES CELL

       @ 250,10 SAY oBrw:oSeek PROMPT oBrw:cSeek SIZE 280,10 PIXEL OF oDlg ;
          COLOR CLR_BLACK, CLR_YELLOW

       SETKEY(VK_RETURN, {|| cPlan := Field_1, oDlg:end()})
       SETKEY(ASC("Y"), {|| IIF(GetKeyState(VK_CONTROL), EVAL({|| oBrw:cseek := ;
              "", oBrw:oSeek:refresh()}), NIL)})

       oBrw:nMarqueeStyle := 5

       oCol               := oBrw:AddCol()
       oCol:cHeader       := " Header 1"
       oCol:bStrData      := {|| Name}
       oCol:bLClickHeader := {|| ORDSETFOCUS("Order1"), EVAL({|| oBrw:cseek := "", ;
                                 oBrw:oSeek:refresh()}), oBrw:refresh()}
       oCol:Adjust()

       oCol               := oBrw:AddCol()
       oCol:cHeader       := " Name"
       oCol:bStrData      := {|| Name}
       oCol:nHeadStrAlign := NCENTER
       oCol:bLClickHeader := {|| ORDSETFOCUS("Name"), EVAL({|| oBrw:cseek := "", ;
                                 oBrw:oSeek:refresh()}), oBrw:refresh()}
       oBrw:aCols[2] :bClrStd := {|| {CLR_WHITE, IIF(FILE(ALLTRIM(Dfile) + TABLE_EXT), ;
                                        CLR_HBLUE, CLR_HRED )}}
       oCol:Adjust()

       oCol               := oBrw:AddCol()
       oCol:cHeader       := " Supplier No. "
       oCol:bStrData      := {|| Sup_no}
       oCol:nHeadStrAlign := NCENTER
       oCol:Adjust()


       oBrw:bClrSel := {|| {CLR_CYAN, CLR_GREEN}}
       oBrw:CreateFromCode()

       ACTIVATE DIALOG oDlg CENTERED ON PAINT oBrw:setfocus()
       RELEASE FONT oFont
 
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: Why xBrowse displays all fields ?

Postby nageswaragunupudi » Tue Jan 25, 2011 4:31 am

Using AUTOCOLS clause sets all fields from the DBF. Instead specify the fields names in the columns clause.

For the above example, please create xbrowse this way:
Code: Select all  Expand view
      DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-14
       DEFINE DIALOG oDlg SIZE 637,600 PIXEL ;
          TITLE "Sample Records" ;
          FONT oFont

       @ 10,10 XBROWSE oBrw SIZE 300,230 PIXEL OF oDlg ;
          COLUMNS "Name",     "Name", "Sup_no" ;
          HEADERS "Header 1", "Name", "Supplier No." ;
          SORT    "Order1",   "Name" ;
          ALIAS "Sample" AUTOSORT LINES CELL

       oBrw:nHeadStrAligns := AL_CENTER

       @ 250,10 SAY oBrw:oSeek PROMPT oBrw:cSeek SIZE 280,10 PIXEL OF oDlg ;
          COLOR CLR_BLACK, CLR_YELLOW

       oBrw:nMarqueeStyle := 5

       SETKEY(VK_RETURN, {|| cPlan := Field_1, oDlg:end()})
       SETKEY(ASC("Y"), {|| IIF(GetKeyState(VK_CONTROL), oBrw:Seek(), NIL)})


       oBrw:bClrSel := {|| {CLR_CYAN, CLR_GREEN}}
       oBrw:CreateFromCode()

       ACTIVATE DIALOG oDlg CENTERED ON INIT ( oBrw:SetFocus(), .f. )
       RELEASE FONT oFont

 
Regards

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

Re: Why xBrowse displays all fields ?

Postby HunterEC » Tue Jan 25, 2011 4:34 am

Rao:

Thank you. Now the incremental seek does not work. Any thoughts ?
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: Why xBrowse displays all fields ?

Postby nageswaragunupudi » Tue Jan 25, 2011 4:39 am

Set order to tag "order1" or tag "name", before starting xbrowse. Or click on the header to change the order. If the order is set to tags "order1" or "name", you see arrow mark on the header and incremental seek works.

By the way may I know why are using field Name for both columns and 1 and 2 both? Alsi may I know the index expressions of tags "order1" and "name" ?
Regards

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

Re: Why xBrowse displays all fields ?

Postby HunterEC » Tue Jan 25, 2011 7:30 am

Rao:

The column fields are: "Name", "LastName", "Sup_no". The column headers does not show the usual arrow as when I used the AUTOCOLS keyword.
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: Why xBrowse displays all fields ?

Postby nageswaragunupudi » Tue Jan 25, 2011 7:41 am

Code: Select all  Expand view
     @ 10,10 XBROWSE oBrw SIZE 300,230 PIXEL OF oDlg ;
          COLUMNS "Name",     "LastName", "Sup_no" ;
          ALIAS "Sample" AUTOSORT LINES CELL
 

Use this simple code and then click on headers. You see the arrow marks as well as they are sorted
Regards

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

Re: Why xBrowse displays all fields ?

Postby HunterEC » Tue Jan 25, 2011 8:10 am

Rao:

Working but still with no arrows on headers and no incremental search. Here's the code:
Code: Select all  Expand view
     aEnv := {RECNO(), ORDSETFOCUS("PlanName")}
      GO TOP

       DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-14
       DEFINE DIALOG oDlg SIZE 568,600 PIXEL ;
          TITLE "Sample Records" ;
          FONT oFont

       @ 10,10 XBROWSE oBrw ;
          SIZE 265,230 PIXEL ;
          OF oDlg ;
          ALIAS "Sample AUTOSORT LINES CELL

       @ 250,10 SAY oBrw:oSeek PROMPT oBrw:cSeek SIZE 255,10 PIXEL OF oDlg ;
          COLOR CLR_BLACK, CLR_YELLOW

       SETKEY(VK_RETURN, {|| cPlan := Pl_sname, oDlg:end()})
       SETKEY(ASC("
Y"), {|| IIF(GetKeyState(VK_CONTROL), EVAL({|| oBrw:cseek := ;
              "
", oBrw:oSeek:refresh()}), NIL)})

       oBrw:nMarqueeStyle := 5

       oCol               := oBrw:AddCol()
       oCol:cHeader       := "
Name"
       oCol:bStrData      := {|| Name}
       oCol:bLClickHeader := {|| ORDSETFOCUS("
Order1"), EVAL({|| oBrw:cseek := "", ;
                                 oBrw:oSeek:refresh()}), oBrw:refresh()}
       oCol:Adjust()

       oCol               := oBrw:AddCol()
       oCol:cHeader       := "
Last Name"
       oCol:bStrData      := {|| LastName}
       oCol:nHeadStrAlign := NCENTER
       oCol:bLClickHeader := {|| ORDSETFOCUS("
Name"), EVAL({|| oBrw:cseek := "", ;
                                 oBrw:oSeek:refresh()}), oBrw:refresh()}
       oCol:Adjust()

       oCol               := oBrw:AddCol()
       oCol:cHeader       := "
Supplier No "
       oCol:bStrData      := {|| Sup_no}
       oCol:nHeadStrAlign := NCENTER
       oCol:Adjust()

       oBrw:CreateFromCode()

       ACTIVATE DIALOG oDlg CENTERED ON PAINT oBrw:setfocus()
       RELEASE FONT oFont



Also, I'm still creating the columns one at a time because my goal is to practice with xBrowse until I can made a generic xBrowse routine where you pass the column(s) array and the coordinates and it creates a new one. This will avoid creating, manually, a new xBrowse for each table I need to display. I used to do this on Clipper/DOS with TBrowse. Any thoughts on this my friend ? Thank you very much for your help.
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: Why xBrowse displays all fields ?

Postby nageswaragunupudi » Tue Jan 25, 2011 9:12 am

Please do NOT use oCol:AddCol() and the related code.
If you can, please send your dbf and cdx files zipped to my email address and I shall give u a simple working program

nageswaragunupudi@gmail.com
Regards

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

Re: Why xBrowse displays all fields ?

Postby nageswaragunupudi » Tue Jan 25, 2011 9:14 am

Code: Select all  Expand view
Also, I'm still creating the columns one at a time because my goal is to practice with xBrowse until I can made a generic xBrowse routine where you pass the column(s) array and the coordinates and it creates a new one

If you want to use xbrowse the right way please stop using the old method of oCol:AddCol() and oCol:bStrData.
If you insist on this old method, may not expect many xbrowse features to work.
Regards

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

Re: Why xBrowse displays all fields ?

Postby Horizon » Tue Jan 25, 2011 11:36 am

Hi Mr. Rao,

I use bStrData also as below.

Code: Select all  Expand view
  if ! Empty( oCol := oBrw:oCol( "Türü" ) )
      oCol:bStrData := { |o| nAt:=ASCAN(aMasraf_Turu[1],(oBrw:cAlias)->T_9),If(nAt>0, aMasraf_Turu[2,nAt], "") }
      oCol:nWidth := 120
   endif


How can change bStrData line?

Thanks,
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Why xBrowse displays all fields ?

Postby nageswaragunupudi » Tue Jan 25, 2011 11:50 am

Instead of bStrData, please assign the value to bEditValue and leave the bStrData for internal use of XBrowse.

Use of bStrData is deprecated, since it is mainly used for internal use of xBrowse. However the backward compatibility with legacy applications is retained, though many of the xbrowse features are not available in case of such usage.

From your codeblock, I understand you were using OzLib's XBrowse class earlier. In such a case, please note one major difference. OzLib evaluates bStrData with the column object as a parameter. FWH's xbrowse does not provide any parameter while evaluating bStrData. If any of your codeblocks are using this parameter, the usage will fail. You may keep this in mind while porting your applications.
Regards

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

Re: Why xBrowse displays all fields ?

Postby Horizon » Tue Jan 25, 2011 1:04 pm

Hi,

Code: Select all  Expand view
From your codeblock, I understand you were using OzLib's XBrowse class earlier. In such a case, please note one major difference. OzLib evaluates bStrData with the column object as a parameter. FWH's xbrowse does not provide any parameter while evaluating bStrData. If any of your codeblocks are using this parameter, the usage will fail. You may keep this in mind while porting your applications.


No, I did not use OzLib's XBrowse. I use native FWH class. In my example I have an two dimensional array as below. The main approach is that print the detail description of T_9 (this is the fieldname that contain "U" or "I" or "F" etc.) T_9 is described in COLUMN clause in XBROWSE.

Code: Select all  Expand view
aMasraf_Turu := {}
aAdd(aMasraf_Turu,{"U","I","F"})
aAdd(aMasraf_Turu,{"U.S.A","ITALY","FRANCE"})


Should I describe it like below.

Code: Select all  Expand view
oBrw:Description:={ || nAt:=ASCAN(aMasraf_Turu[1],(oBrw:cAlias)->T_9),If(nAt>0, aMasraf_Turu[2,nAt], "") }
oBrw:Description:nOrder := 5
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Why xBrowse displays all fields ?

Postby nageswaragunupudi » Tue Jan 25, 2011 1:26 pm

until I can made a generic xBrowse routine where you pass the column(s) array and the coordinates and it creates a new one.

If this is your objective, the approach I have been recommending is better. Please do not go the way of oBrw:AddCol(). This way you can not produce an efficient and bug-free code easily.

If only you like to take my advice, I can take you through some steps to create parmetrised creation of xbrowse.
Regards

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

Re: Why xBrowse displays all fields ?

Postby nageswaragunupudi » Wed Jan 26, 2011 2:21 am

Before we go to parametrized browse function, let us see the straight forward browse sample. This is the first sample you were working with.
Code: Select all  Expand view
#include "FiveWin.Ch"
#include "ord.ch"
#include "xbrowse.ch"

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

REQUEST DBFCDX

static cDbf := "SAMPLE.DBF"  // change this line for your path

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

function Main()

   MsgInfo( TestDialog() )

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( 'A', .t. )
    SetGetColorFocus()

return

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

static function TestDialog()

   local oDlg, oBrw, oFont, cRet
   local bSeek

   USE (cDbf) NEW SHARED
   SET ORDER TO TAG ORDER1
   GO TOP

   DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 637,600 PIXEL ;
      TITLE "Sample Records" ;
      FONT oFont

   @ 10,10 XBROWSE oBrw SIZE 300,230 PIXEL OF oDlg ;
      COLUMNS "Name",     "LastName", "Sup_no" ;
      HEADERS "Header 1", "Name", "Supplier No." ;
      ALIAS "Sample" AUTOSORT LINES CELL NOBORDER


   @ 250,10 SAY oBrw:oSeek PROMPT oBrw:cSeek SIZE 280,10 PIXEL OF oDlg ;
      COLOR CLR_BLACK, CLR_YELLOW

   // Next two lines are a Small work around for case insensitive seek
   bSeek      := oBrw:bSeek
   oBrw:bSeek := { |c| Eval( bSeek, Upper( c ) ) }
   // The above two lines will not needed from FWH 11.1 onwards


   SETKEY( VK_RETURN, { || cRet := FIELD->NAME, oDlg:end() } )
   SETKEY( Asc("Y"),  { || If( GetKeyState( VK_CONTROL ), oBrw:Seek(), nil ) } )


   WITH OBJECT oBrw
      :bClrSelFocus     := { || { CLR_WHITE, CLR_GREEN } }
      :nHeadStrAligns   := AL_CENTER
      :nStretchCol      := STRETCHCOL_WIDEST
      :nMarqueeStyle    := 5
   END

   oBrw:CreateFromCode()

   ACTIVATE DIALOG oDlg CENTERED ON INIT ( oBrw:SetFocus(), .f. )
   RELEASE FONT oFont

return cRet

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

Please test this program.
In the next sample I show how we do this passing parameters to a general browse function.

Please note that the main code to construct the browse is simple one line
Code: Select all  Expand view


   @ 10,10 XBROWSE oBrw SIZE 300,230 PIXEL OF oDlg ;
      COLUMNS "Name",     "LastName", "Sup_no" ;
      HEADERS "Header 1", "Name", "Supplier No." ;
      ALIAS "Sample" AUTOSORT LINES CELL NOBORDER
 


Image
Regards

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

Re: Why xBrowse displays all fields ?

Postby HunterEC » Wed Jan 26, 2011 4:20 am

Rao:

Worked flawlessly, thank you very much. I'm waiting for your generic browsing function. 8)
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 103 guests