Page 1 of 1

XBROWSE FIELDS with Name in Array

PostPosted: Thu Apr 27, 2023 9:51 pm
by Jimmy
hi,

i want to "pick" Name of FIELD from DBSTRUCT() an use it with XBROWSE
now i have Names of FIELD in Array but how to pass it to XBROWSE :?:
Code: Select all  Expand view
90, 10 XBROWSE oBrw1 FIELDS One->First, One->Last ;

this Style need to "know" Name of FIELD

what i like to have are this
Code: Select all  Expand view
90, 10 XBROWSE oBrw1 FIELDS aMyFields

! Note : i do NOT want to Browse a Array, i want to use DBF but Name of FIELD are in Array "aMyFields"

Re: XBROWSE FIELDS with Name in Array

PostPosted: Thu Apr 27, 2023 10:42 pm
by Jimmy
hi,

i now have
Code: Select all  Expand view
  // store Array
   SP_aDbfStruct( DBSTRUCT() )

   @ 50,  2 XBROWSE oBrwDBF FIELDS Struct2String()


Code: Select all  Expand view
FUNCTION SP_aDbfStruct( xValue )
STATIC aDbfStruct :=  {}
   IF PCOUNT() > 0
      aDbfStruct := ACLONE( xValue )
   ENDIF
RETURN aDbfStruct


Code: Select all  Expand view
FUNCTION Struct2String()
LOCAL aStruc := SP_aDbfStruct()  // recall Array
LOCAL ii, iMax,cField , cRet := ""

   iMax := LEN(aStruc)
   FOR ii := 1 TO iMax
      cField := aStruc[ii][DBS_NAME]
      cRet += CHR(34) + cField + CHR(34)
      IF ii <> iMax
         cRet += ", "
      ENDIF
   NEXT

   FWLOG cRet
RETURN cRet
 

now XBROWSE does display all Column + 1 Extra Column which display String i got from Function Struct2String() :shock:

Image
what i´m doing wrong :?:

p.s. Fieldname will later come from Picklist
Image

Re: XBROWSE FIELDS with Name in Array

PostPosted: Fri Apr 28, 2023 8:16 pm
by Jimmy
i try to ask other Way

i saw Sample
Code: Select all  Expand view
   @ 0, 0 XBROWSE oBrw OF oDlg FIELDS One->First, One->Last
or
   @ 0, 0 XBROWSE oBrw OF oDlg COLUMNS 1,2


which both can "reduce" Column to DBF FIELD which i want

but that is "hardcode" an now i have a "Picklist" for it
so i try
Code: Select all  Expand view
   @ 0, 0 XBROWSE oBrw OF oDlg FIELDS FieldNameFunc()
or
   @ 0, 0 XBROWSE oBrw OF oDlg COLUMNS FiledNumberFunc()

both Function return String, but it seems not to work as i want
i still get "all" FIELD of DBF display in XBROWSE ...

so how is the right Syntax for XBROWSE or XCbrowseNew( ) :?:

Re: XBROWSE FIELDS with Name in Array

PostPosted: Sat Apr 29, 2023 6:18 am
by Jimmy
hi,

ok got it this Way

Code: Select all  Expand view
XBROWSE oBrwDBF COLUMNS ColsNumber( DBSTRUCT() ) SIZE nWidth - 20, nHeight - 90 PIXEL OF oWnd ;
    FONT oFontDefault ;
    COLOR BFcolor, BGcolor ;
    ALIAS cAlias CELL LINES NOBORDER FASTEDIT AUTOCOLS

FUNCTION ColsNumber(aDbfStruct)
LOCAL aStruc := SP_aDbfStruct()  // Array from Picklist
LOCAL ii, iMax, nPosi
LOCAL aRet := {}

   iMax := LEN( aStruc )
   FOR ii := 1 TO iMax
      nPosi := ASCAN(aDbfStruct,{|x| x[DBS_NAME] = aStruc[ii][DBS_NAME] } )
      IF nPosi > 0
         AADD(aRet, nPosi)
      ENDIF
   NEXT
RETURN aRet

so it must be a Array which Function return

---

when use "reduce" FIELDs in XBROWSE and call
Code: Select all  Expand view
  oBrwDBF:EditSource( .T. )

it will open Form which include all FIELDs of DBF :shock:
how can i change to edit only FIELD that i define ?

---

i have try again Option FIELDS
@ 50, 2 XBROWSE oBrwDBF FIELDS Struc2Array( cAlias )
@ 50, 2 XBROWSE oBrwDBF FIELDS Struc2String( cAlias )

Code: Select all  Expand view
STATIC FUNCTION Struc2String( cAlias )
LOCAL aStruc := SP_aDbfStruct()
LOCAL ii, iMax, cField, cRet := ""

   iMax := LEN( aStruc )
   FOR ii := 1 TO iMax
      cField := aStruc[ ii ] [ DBS_NAME ]
      //       cRet += CHR( 34 ) + cField + CHR( 34 )
      cRet += "'" + cAlias + "->" + cField + "'"
      //       cRet += cAlias +"->"+ cField
      IF ii <> iMax
         cRet += ", "
      ENDIF
   NEXT
RETURN cRet


Code: Select all  Expand view
STATIC FUNCTION Struc2Array( cAlias )
LOCAL aStruc := SP_aDbfStruct()
LOCAL ii, iMax, cField, aRet := {}

   iMax := LEN( aStruc )
   FOR ii := 1 TO iMax
      cField := aStruc[ ii ] [ DBS_NAME ]
      AADD( aRet, cField )
   NEXT

RETURN aRet

both show all FIELDs of DBF + 1 "extra" Column ...

so how will it work right when use FIELDS and a Function :idea:

Re: XBROWSE FIELDS with Name in Array

PostPosted: Sat Apr 29, 2023 2:24 pm
by nageswaragunupudi
1) Important: Please do not use FIELDS clause. This was originally meant to facilitate easy migration from WBrowse.
Using COLUMNS clause allows us to to take full power of XBrowse. Using FIELDS clause makes XBrowse dumb

2) If we want to specify all columns of the DBF, there is no need for our program to read the structure and specify the column names.
Use the clause AUTOCOLS instead of COLUMNS .... clause.
When we use AUTOCOLS clause, XBrowse itself reads the DBSTRUCT() and builds all the columns suitably, including the sort orders.

Example:
Code: Select all  Expand view
[code]@ r,c XBROWSE oBrw SIZE w,h PIXEL OF oDlg ;
DATASOURCE "aliasname" AUTOCOLS[/code] ;
<otherClauses>


Still just for academic interest, just to know how to generate column names from DBSTRUCT():
Code: Select all  Expand view
@ r,c XBROWSE oBrw SIZE w,h PIXEL OF oDlg ;
DATASOURCE "CUSTOMER" ;
COLUMNS ArrTranspose( CUSTOMER->(DBSTRUCT()))[ 1 ] ....

though we do not recommend this because this is totally unnecessary

Re: XBROWSE FIELDS with Name in Array

PostPosted: Sat Apr 29, 2023 3:11 pm
by nageswaragunupudi
Interesting use of DBSTRUCT()

Code: Select all  Expand view
  USE CUSTOMER
   aCols := ArrTranspose( DBSTRUCT() )[ 1 ]
   aCols := AShuffle( aCols, 2, 9 )

   DEFINE WINDOW oWnd
   @ 0,0 XBROWSE oBrw SIZE 0,0 PIXEL OF oWnd ;
      DATASOURCE "CUSTOMER" ;
      COLUMNS aCols ;
      CELL LINES NOBORDER

   oBrw:AutoFit()
   oBrw:CreateFromCode()

   oWnd:nWidth    := 900
   oWnd:nHeight   := 300

   ACTIVATE WINDOW oWnd CENTERED

   return nil
 

Image

Re: XBROWSE FIELDS with Name in Array

PostPosted: Sat Apr 29, 2023 3:34 pm
by karinha
WOW. Super interesting. One can shuffle the content of xBrowse()

Many thanks.

Regards, saludos.

Re: XBROWSE FIELDS with Name in Array

PostPosted: Sat Apr 29, 2023 5:22 pm
by nageswaragunupudi
it will open Form which include all FIELDs of DBF :shock:
how can i change to edit only FIELD that i define ?


Code: Select all  Expand view
METHOD EditSource( lNew, cFieldList, lNavigate, aInitVals )

Re: XBROWSE FIELDS with Name in Array

PostPosted: Sun Apr 30, 2023 9:06 pm
by Jimmy
hi,
nageswaragunupudi wrote:
Code: Select all  Expand view
METHOD EditSource( lNew, cFieldList, lNavigate, aInitVals )

ah, ok thx for Answer

how does"cFieldList" look like and what Delimiter is used :?:

would be nice if it also accept a Array with (reduce) Structure of DbStruct()

Re: XBROWSE FIELDS with Name in Array

PostPosted: Tue May 02, 2023 2:54 pm
by Marc Venken

Re: XBROWSE FIELDS with Name in Array

PostPosted: Tue May 02, 2023 3:24 pm
by Jimmy
hi Marc ,
Marc Venken wrote:Some info :
viewtopic.php?f=3&t=37097

ok, thx for link

Re: XBROWSE FIELDS with Name in Array

PostPosted: Tue May 02, 2023 3:27 pm
by nageswaragunupudi
how does"cFieldList" look like and what Delimiter is used :?:


Comma delimited
Eg: "FIRST,CITY,SALARY,..."

We can easily convert an array like DbStruct() to list like this:
FW_ArrayAsList( ArrTranspose( aStruct )[ 1 ] )

Re: XBROWSE FIELDS with Name in Array

PostPosted: Tue May 02, 2023 3:31 pm
by Jimmy
hi,
nageswaragunupudi wrote:Comma delimited
Eg: "FIRST,CITY,SALARY,..."

thx for Answer

nageswaragunupudi wrote:We can easily convert an array like DbStruct() to list like this:
FW_ArrayAsList( ArrTranspose( aStruct )[ 1 ] )

ah, that is nice :)