XBROWSE FIELDS with Name in Array

XBROWSE FIELDS with Name in Array

Postby Jimmy » Thu Apr 27, 2023 9:51 pm

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  RUN
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  RUN
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"
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: XBROWSE FIELDS with Name in Array

Postby Jimmy » Thu Apr 27, 2023 10:42 pm

hi,

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

   @ 50,  2 XBROWSE oBrwDBF FIELDS Struct2String()


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


Code: Select all  Expand view  RUN
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
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: XBROWSE FIELDS with Name in Array

Postby Jimmy » Fri Apr 28, 2023 8:16 pm

i try to ask other Way

i saw Sample
Code: Select all  Expand view  RUN
   @ 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  RUN
   @ 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( ) :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: XBROWSE FIELDS with Name in Array

Postby Jimmy » Sat Apr 29, 2023 6:18 am

hi,

ok got it this Way

Code: Select all  Expand view  RUN
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  RUN
  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  RUN
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  RUN
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:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: XBROWSE FIELDS with Name in Array

Postby nageswaragunupudi » Sat Apr 29, 2023 2:24 pm

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  RUN
[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  RUN
@ 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
Regards

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

Re: XBROWSE FIELDS with Name in Array

Postby nageswaragunupudi » Sat Apr 29, 2023 3:11 pm

Interesting use of DBSTRUCT()

Code: Select all  Expand view  RUN
  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
Regards

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

Re: XBROWSE FIELDS with Name in Array

Postby karinha » Sat Apr 29, 2023 3:34 pm

WOW. Super interesting. One can shuffle the content of xBrowse()

Many thanks.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7831
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: XBROWSE FIELDS with Name in Array

Postby nageswaragunupudi » Sat Apr 29, 2023 5:22 pm

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  RUN
METHOD EditSource( lNew, cFieldList, lNavigate, aInitVals )
Regards

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

Re: XBROWSE FIELDS with Name in Array

Postby Jimmy » Sun Apr 30, 2023 9:06 pm

hi,
nageswaragunupudi wrote:
Code: Select all  Expand view  RUN
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()
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: XBROWSE FIELDS with Name in Array

Postby Marc Venken » Tue May 02, 2023 2:54 pm

Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1437
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: XBROWSE FIELDS with Name in Array

Postby Jimmy » Tue May 02, 2023 3:24 pm

hi Marc ,
Marc Venken wrote:Some info :
viewtopic.php?f=3&t=37097

ok, thx for link
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: XBROWSE FIELDS with Name in Array

Postby nageswaragunupudi » Tue May 02, 2023 3:27 pm

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 ] )
Regards

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

Re: XBROWSE FIELDS with Name in Array

Postby Jimmy » Tue May 02, 2023 3:31 pm

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 :)
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 117 guests