Configurate xBrowser from dbf data issues

Configurate xBrowser from dbf data issues

Postby Marc Venken » Sat Feb 05, 2022 9:17 pm

I have some problems with the configuration of the folowing xbrowse settings.

I call a Xbrowse Builders that i gonne use for my projects. It works ok for the general settings, but now I also want to set the color actions from the dbf files.

In the dbf I have the folowing data : I read the data I need into a multidim. array : aBrwcols


Code: Select all  Expand view

I call the function :
   oBrw[5] = getXBrowser("WEBSHOP",oFld:aDialogs[5])


function getXbrowser(cData,oTarget)

   // code to get the data from the dbf...

   @ nTop,nLeft XBROWSE oBrw size nBreed,nHoogte PIXEL OF oTarget font oFont ;
      DATASOURCE cDbf ;
      COLUMNS aVeld ;
      HEADERS aKop ;
      COLSIZES aSizes ;
      AUTOSORT CELL LINES NOBORDER FOOTERS

   oBrw:bToolTips   := ;
         { | oBrw,r,c,f,oMouseCol,nMouseRow| MyColToolTip( oBrw,r,c,f,oMouseCol,nMouseRow ) }

   oBrw:bRClicked     := { |r,c,f,oStru| msgWait(oBrw:aCols[oBrw:nColSel]:VALUE,,2),oClp:SetText(oBrw:aCols[oBrw:nColSel]:VALUE) }

   StyleBrowse(oBrw, aBrwGet, aBrwEdit ,cData )  // will generate Pijama and several settings
   XbrSetupBar( oBrw , Cdata )  //  generate a Bar


// generate a loop with all the actions that are needed to color cels.
//  like  :  if(webshop->bruto > 0,.t.,.f.)
//  or like    :  if (webshop->prijspromo  <> webshop-> bruto , .t. , .f.) 

   if len(aBrwCols) > 0   // there are column that we want to color with a condition
     for i = 1 to len(aBrwCols)
        cVeld = aBrwCols[i][1]             //  fieldname/header  to use  :  Bruto
        cExpres = aBrwCols[i][2]         // the exprencion to validate : if(webshop->bruto > 0,.t.,.f.)    Will always return a .t. or .f.
        cFront = val(aBrwCols[i][3])     //  DEC color value front : 0
        cBack = val(aBrwCols[i][4])     // DEC  color value back : 16777130   //  I was not able to use constant values like : CLR_GREEN
        cZoek = oBrw:&cVeld:value     // is the the value of the field of the browse to compare with
        lZoek = &cExpres  //  .t. of .f.   // Exucute the expression to get a .t. or .f.

        oBrw:&cVeld:bClrStd := { || if ( lZoek  , ;
        {nClrTxtBrw, cBack } ,;
        {nClrTxtBrw, If( oBrw:KeyNo() % 2 == 0, CLR_BROWSE2, CLR_BROWSE1 )}    )}
     next
   endif

//  Rest code ...  

 


This code is working for 1 row, and then keeps the values the same for every folowing row, so the condition is not changing.


Second test :

When I do this (call the function and code the color after it, it works

oBrw[5] = getXBrowser("WEBSHOP",oFld:aDialogs[5])
oBrw[5]:bruto:bClrStd := { || If( oBrw[5]:bruto:value <> oBrw[5]:prijsnew:value,;
{nClrTxtBrw, CLR_HGREEN } ,;
{nClrTxtBrw, If( oBrw[5]:KeyNo() % 2 == 0, CLR_BROWSE2, CLR_BROWSE1 )} )}

BTW : the extra code in the bClrStd:= is for the pijama layout of the browse to work with color setting
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1417
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Configurate xBrowser from dbf data issues

Postby Marc Venken » Tue Feb 08, 2022 3:29 pm

Do i better try to make a sample to see what can be done ?
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1417
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Configurate xBrowser from dbf data issues

Postby leandro » Thu Feb 10, 2022 11:38 am

Marc buenos días como vas?

Una idea, a nosotros nos sirve haciendo una llamada a una función, no se si sea lo que buscas, es lo que entendí que necesitas hacer.

Code: Select all  Expand view


    @ 100, 5 XBROWSE oBrw ;
    SIZE 385 ,160 OF oSelf:oDlgSpt PIXEL ;
    LINES STYLE FLAT NOBORDER ;
    DATASOURCE ::aRspNm AUTOCOLS

    ReArrangeCols( oBrw, ::aCols1 )

    WITH OBJECT oBrw
        :lRecordSelector        := .T.
        :lHScroll           := .T.
        :lVScroll           := .T.
        :l2007              := .F.
        :lFitGridHeight         := .T.
        :nHeaderHeight          := 21
        :nRowHeight         := 21
        :nMarqueeStyle          := MARQSTYLE_HIGHLROW
        :lColDividerComplete    := .t.
        :nColorPen          := CLR_HGRAY
        :lFullGrid          := .T.
        :nStretchCol            := STRETCHCOL_LAST
        :bClrHeader         := { || { CLR_WHITE, oLamcla:nClrBrwCab, CLR_HGRAY } }
        :lFooter            := .t.
        :nFooterLines           := 1
        :nFooterHeight          := 25
        :nFreeze                := 4
        :bRClicked          := {|nRow, nCol | if(!::lNueva,::mRegNomi( nRow,nCol,oBrw, cbModi, cbEnv, cnImpPg, cbElm, cbAgre, cnEDian, cbBrCmp ),) }
        :bKeyDown           := {|nKey,oGet,nCol|::TecItemNomi(nKey,oGet,nCol, cbModi, cbEnv, cnImpPg, cbElm, cbAgre, cnEDian, cbGraba)}
        :nRecSelColor           := RGB( 255, 255, 255 )

        :bClrStd            := {|| if(Len( ::aRspNm ) > 0 , ;
                                { CLR_BLACK,clrEstFondo(::aRspNm[oBrw:nArrayAt]["estado"]) } ,;
                                { CLR_BLACK,clrEstFondo("S") } ) } 
        :bClrSelFocus       := {|| if(Len( ::aRspNm ) > 0 , ;
                                { CLR_WHITE,clrEstSelec(::aRspNm[oBrw:nArrayAt]["estado"]) } ,;
                                { CLR_WHITE,clrEstSelec("S") }) }      
        :SetFont( oFont1Cja )
       
    END

    WITH OBJECT oBrw

        //Colocamos los titulos a las columnas
        FOR j:=1 TO len(::aColTt)
            :aCols[j]:cHeader  := ::aColTt[j]
            :aCols[j]:oHeaderFont = oFontCja   
            :aCols[j]:nWidth = ::aColAn[j] 
        NEXT

        //Ahora las especiales
        :aCols[3]:cFooter      = "TOTALES »"
        :aCols[3]:oFooterFont := oFontCja

        :aCols[4]:bClrStd           := {|| { _CLR_GRIS,colorEstado2( ::aRspNm[oBrw:nArrayAt]["estado"] ) }  }
        :aCols[4]:bClrSelFocus  := {|| { CLR_WHITE,colorEstado( ::aRspNm[oBrw:nArrayAt]["estado"] ) }  }
        :aCols[4]:bStrData      := { || if(Len( ::aRspNm ) > 0 , nombreEstado( ::aRspNm[oBrw:nArrayAt]["estado"] ) , "" ) }
   
        :aCols[nColDev]:oFooterFont := oFontCja
        :aCols[nColDev]:bClrStd      = {|| {Rgb(55,55,55),nRGB(212,212,212) }  }
        :aCols[nColDev]:bClrSelFocus = {|| {CLR_WHITE,nRGB(139,139,139) }  }
       
        :aCols[nColDed]:oFooterFont := oFontCja
        :aCols[nColDed]:bClrStd      = {|| {Rgb(55,55,55),nRGB(255,187,187) }  }
        :aCols[nColDed]:bClrSelFocus = {|| {CLR_WHITE,nRGB(255,117,117) }  }

        :aCols[nColPag]:oFooterFont := oFontCja
        :aCols[nColPag]:bClrStd      = {|| {Rgb(55,55,55),nRGB(187,255,187) }  }
        :aCols[nColPag]:bClrSelFocus = {|| {CLR_WHITE,nRGB(0,210,0) }  }
       
        //Colocamos los totales en donde sea necesario
        FOR i:=1 TO len(::aCols1)
            if ::aColTl[i]
                :aCols[i]:nFooterType  := AGGR_SUM
                :aCols[i]:cFooterPicture := oLamcla:PIC7
                :aCols[i]:cEditPicture := oLamcla:PIC7
                :aCols[i]:oFooterFont := oFontCja
            endif
        NEXT
        :MakeTotals()
   
    END

    oBrw:CreateFromCode()
 

.....




****************************
*CAMBIA EL COLOR DE LA CELDA
****************************
Function colorEstado(valor,notas)
if notas==nil
    notas := 0
endif

if notas!=0
    Return nRGB(163,73,164) //morado oscuro
else
    IF valor=="A"
        Return nRGB(139,139,139) //gris oscuro
    ELSEIF valor=="D"
        Return nRGB(0,210,0) //verde oscuro
    ELSEIF valor=="E"
        Return nRGB(255,117,117) //rojo oscuro
    ELSEIF valor=="V"
        Return nRGB(255,117,117) //rojo oscuro
    ELSEIF valor=="I"
        Return nRGB(255,243,21) //Amarillo Oscuro
    ELSEIF valor=="Z"
        Return nRGB(255,243,21) //Amarillo Oscuro
    ELSE
        Return nRGB(94, 174, 255) //Azul Defecto
    ENDIF
endif

*****************************************
*CAMBIA EL COLOR DE LA CELDA SELECCIONADO
*****************************************
Function colorEstado2(valor,notas)
if notas==nil
    notas := 0
endif
if notas!=0
    Return nRGB(219,183,255) //morado claro
else
    IF valor=="A"
        Return nRGB(212,212,212) //gris claro
    ELSEIF valor=="D"
        Return nRGB(187,255,187) //verde claro
    ELSEIF valor=="E"
        Return nRGB(255,187,187) //rojo claro
    ELSEIF valor=="V"
        Return nRGB(255,187,187) //rojo claro
    ELSEIF valor=="I"
        Return nRGB(255,251,164) //Amarillo claro
    ELSEIF valor=="Z"
        Return nRGB(255,251,164) //Amarillo claro
    ELSE
        Return nRGB(255,255,255) //Blanco
    ENDIF
endif
 
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1669
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: Configurate xBrowser from dbf data issues

Postby Marc Venken » Thu Feb 10, 2022 11:46 pm

Hello Leandro, and others...

Estoy bien. Gracias por tu comentario

Long live Google Translate )))

I made a sample program to show the issue that I have. I call a Xbrowse from a function (for many browses in the program)
The testprogram normaly will build 2 dbf's with some data into it and uses the customer.dbf from the samples dir. (put the program there)


If I put the code for coloring cells with a condition insite the function getXbrowser, I get the same color for every row (Green)

oBrw[2] = getXBrowser("CUSTOMERS",oFld:aDialogs[2])

Lines for coloring start from 373 - 387. For the demo I just made a Array with some data.

If I call a function afther I made the getxbrowser, it works ok (Orange)

Code: Select all  Expand view

oBrw[2] = getXBrowser("CUSTOMERS",oFld:aDialogs[2])

oBrw[2]:First:bClrStd := { || If( oBrw[2]:state:value = "IL",;
      {nClrTxtBrw, MY_YELLOW } ,;
      {nClrTxtBrw, If( oBrw[2]:KeyNo() % 2 == 0, CLR_BROWSE2, CLR_BROWSE1 )}    )}
 


Image

So the green cells don't folow the condition.

The idea is to put as many options for Xbrowse inside a DBF and make a xbrowse Builder from it.

Code: Select all  Expand view

#include "fivewin.ch"
#include "Directry.ch"
#include "inkey.ch"
#include 'ord.ch'
#include "ribbon.ch"
#include 'xbrowse.ch'

#define MY_GREEN   nRGB( 145, 214, 124)
#define MY_LIGHTGREEN nRGB( 236, 255, 224)
#define MY_LIGHTYELLOW nRGB( 255, 251, 142)
#define MY_LIGHTBLUE nRGB( 214, 229, 255)
#define MY_PAARS nRGB( 232, 201, 255)
#define MY_YELLOW nRGB( 255, 220, 96)
#Define CLR_BROWSE1     nRGB( 214, 229, 255 )
#Define CLR_BROWSE2     nRGB( 229, 237, 246 )
#Define CLR_BROWSECEL   nRGB(   0,  75, 125 )
#Define CLR_BROWSEROW   nRGB(  73, 118, 185 )
#Define CLR_BROWSEINDEX nRGB( 156, 156, 156 )

#Define CLR_LGREEN     nRGB( 190, 215, 190 )
#Define CLR_SOFTYELLOW nRGB( 255, 251, 225 )
#Define CLR_PINK       nRGB( 255, 128, 128 )
#Define CLR_NBLUE      nRGB( 128, 128, 192 )
#Define CLR_MSPURPLE   nRGB( 0,   120, 215 )
#Define CLR_MSRED      nRGB( 232,  17,  35 )
#Define CLR_MSGRAY     nRGB( 229, 229, 229 )
#define CLR_LIGHTBLUE  nRGB( 214, 229, 255)

ANNOUNCE RDDSYS
REQUEST OrdKeyNo, OrdKeyCount, OrdCreate, OrdKeyGoto
REQUEST DBFCDX, DBFFPT

STATIC oWnd, oDlg, oFont, cClrBack, oBold
STATIC oDlgRB[ 3 ]
STATIC SERVER_PATH, LOCAL_PATH, oFld, CDRIVE, cLocal
STATIC lServer := .F.
//  ADDED BY MARC

STATIC oKlant , oRec
static sys_dbf:={}

static nClrTxtBrw      := CLR_BLACK
static nClrBackBrw     := CLR_WHITE
static lPijama         := .T.

FUNCTION Main()

   LOCAL sys_versie := "Dec 2021 - 02/12"
   LOCAL cErrorLogFileName := "MyLog.log"
   LOCAL oFol, oDlg, oRBar, oMenu, oMenuWnd, oBrush1, oGr, oGr1, oGr2, oGr3, ;
         oGr9, oSay1, oBmp, oFont1, oCursor, oBtn2, oBtn3, oBtn4

   RDDSETDEFAULT("DBFCDX")

   FW_SetUnicode( .T. )
   SetBalloon( .T. ) // Balloon shape required for tooltips
   SkinButtons()
   SetGetColorFocus( MY_LIGHTGREEN )
   xbrNumFormat( "E", .T. )  // "E" for European, "A" for American and others // .t. for showing thousand separators

   Forumsetup()  // Make forumdatabases for testing

   DEFINE FONT oFont1 NAME "Arial" SIZE 0, - 15 // BOLD

   DEFINE CURSOR oCursor HAND
   DEFINE BRUSH oBrush1 COLOR nRGB( 223, 233, 244 )

   DEFINE WINDOW oWnd TITLE "Maveco Bedrijfskleding " + FWVERSION ;
      FROM 0, 0 TO 1030, 1920 pixel MDI MENU oMenu BRUSH oBrush1

   DEFINE RIBBONBAR oRBar WINDOW oWnd PROMPT "Klanten", "Leveranciers", "Ingeven Documenten";
      HEIGHT 130 TOPMARGIN 25

//  Databases =============================
   ADD GROUP oGr  RIBBON oRBar TO OPTION 1 PROMPT "Databases" width 130 ;
      BITMAP "bitmaps\fivetech.BMP"

   @ 02, 05 ADD BUTTON oBtn2 GROUP oGr BITMAP "bitmaps\cut16.BMP" ;
      SIZE 75, 20 PROMPT "Customers"  MOSTLEFT round ;
      action ( Marc_FolderEx(oWnd) )

   ADD GROUP oGr2  RIBBON oRBar TO OPTION 1 PROMPT "Documents" width 130 ;
      BITMAP "bitmaps\fivetech.BMP"


//  X-Browsers =============================

   ADD GROUP oGr7  RIBBON oRBar TO OPTION 1 PROMPT "XBrowsers" width 130 ;
      BITMAP "bitmaps\fivetech.BMP"

   ADD GROUP oGr9 RIBBON oRBar TO OPTION 1 PROMPT "Exit" width 70 ;
      BITMAP "bitmap\fivetech.bmp"

//  Exit =============================

   @ 15, 20 ADD BUTTON oBtn4 GROUP oGr9 BITMAP "bitmaps\32x32\quit.BMP" ;
      SIZE 34, 52 PROMPT "Exit" action( oWnd:End() )

   SET MESSAGE OF oWnd TO "Version : " + sys_versie ;
      CENTERED CLOCK KEYBOARD 2007

   WndCenter( oWnd:hWnd )

   ACTIVATE WINDOW oWnd MAXIMIZED


   oBrush1:End()
   oRBar:End()

RETURN NIL

CLASS TSeek STATIC //  From Xbrowse seek function ?

   DATA oBrw

   METHOD New( oBrw ) CONSTRUCTOR
   METHOD SetText( c ) INLINE ::oBrw:RefreshFooters()

ENDCLASS

METHOD New( oBrw ) CLASS TSeek  //  From Xbrowse seek function ?

   ::oBrw   := oBrw

RETURN Self

FUNCTION del_row( oBrw )

   IF MsgYesNo( "Deze regel wissen" )

      oBrw:delete()

   ENDIF

RETURN NIL


FUNCTION Marc_FolderEx( oWnd )

   //  Locals added by Marc
   local oFont1,oBold,oFont,oFont3,oFonts,oFontXS
   local cCol, oBrush
   LOCAL aVelden := ARRAY(10)  // oBrw[10]
   LOCAL oBrw    := ARRAY(10)  // oBrw[10]
   LOCAL hBmp    := ReadBitmap( 0, "bitmaps\search.bmp" )

   //
   LOCAL oDlg, oFld, oBarDialog, cTitle, aGrad, oOk, oExit
   LOCAL cDenominazione := ""
   LOCAL cIndirizzo     := ""
   LOCAL oSay      := ARRAY(4)
   LOCAL aGet      := ARRAY(4)
   LOCAL cCompl    := REPLICATE( ".",  9 )
   LOCAL oSilDrawLi
   LOCAL SilDrawLi := REPLICATE( "_", 50 )
   LOCAL EmailSilv := SPACE(50)


   //OpenDatabases("KLANTEN")

   cTitle := "Marc Test : Systems Folders and Xbrowse Builder"

   SET _3DLOOK ON

   SetGetColorFocus( CLR_LGREEN ) // COR EM TODOS OS GETS DOS DIALOGOS.

   tGet():lDisColors  := .F.   // WHEN( .F. ) COR.
   tGet():nClrTextDis := CLR_HBLUE
   tGet():nClrPaneDis := CLR_SOFTYELLOW

   SetBalloon( .T. ) // Balloon shape required for tooltips

   SkinButtons()

   aGrad := { { 1, CLR_WHITE, CLR_LIGHTBLUE } }

   DEFINE FONT oFont1 NAME "Ms Sans Serif" SIZE 0, - 8 BOLD
   DEFINE FONT oBold NAME 'CALIBRI' SIZE 0, - 12 BOLD
   DEFINE FONT oFont NAME "CALIBRI" SIZE 0, - 14
   DEFINE FONT oFont3 NAME "Segoe UI" SIZE 0, - 12
   DEFINE FONT oFontS NAME "Segoe UI" SIZE 0, - 09
   DEFINE FONT oFontXS NAME "Segoe UI" SIZE 0, - 08

   DEFINE BRUSH oBrush FILE "Bitmaps\BackGrnd\Stone.bmp"

   DEFINE DIALOG oDlg FROM 60,0 to 750,1900 PIXEL TRUEPIXEL TITLE cTitle;
      GRADIENT aGrad

   oDlg:lHelpIcon := .F.

   DEFINE BUTTONBAR oBarDialog OF oDlg SIZE 80, 80 2007 BOTTOM NOBORDER

   @ 3, 3 FOLDEREX oFld SIZE oDlg:nWidth, oDlg:nHeight - oBarDialog:nheight  ;
      PROMPT "Basic", "Builder" ;
      BITMAPS "..\bitmaps\alphabmp\Facebook.bmp",                            ;
              "..\bitmaps\alphabmp\viddler.bmp"                              ;
      FONT oFont PIXEL COLOR CLR_MSGRAY TAB HEIGHT 25 ROUND 5

   oFld:aEnable = { .T., .T. }
   oFld:SetOption( 1 )
   oFld:Show()

   // Marc, write the code here on the spot.

   //  FOLDER 1  -----------------------------------------------------------------------------------------------

   aVelden[1] :=  { ;
      { "ID", "ID", NIL,  90 }, ;
      { "First", "First", NIL,  350 }, ;
      { "Last", "Last", NIL, 300 }, ;
      { "Street", "Street", NIL, 300 }, ;
      { "City", "City", NIL, 200 }, ;
      { "Zip", "Zip", NIL, 150 } }

   @ 0, 0 XBROWSE oBrw[ 1 ] size - 05, - 20 PIXEL OF oFld:aDialogs[ 1 ] font oFont ;
      DATASOURCE "customer" ;
      COLUMNS aVelden[1] ;
      AUTOSORT CELL LINES NOBORDER FOOTERS

   WITH OBJECT oBrw[ 1 ]
      :bKeyDown   := {| k | IF ( K == VK_DELETE, Del_row( oBrw[ 1 ] ), NIL ) }
      // Designing is here

   END
   oBrw[ 1 ]:CreateFromCode()
   oBrw[ 1 ]:setfocus()

   //  FOLDER 2  -----------------------------------------------------------------------------------------------

   oBrw[2] = getXBrowser("CUSTOMERS",oFld:aDialogs[2])

   // This way the colors are painted correct
   oBrw[2]:First:bClrStd := { || If( oBrw[2]:state:value = "IL",;
      {nClrTxtBrw, MY_YELLOW } ,;
      {nClrTxtBrw, If( oBrw[2]:KeyNo() % 2 == 0, CLR_BROWSE2, CLR_BROWSE1 )}    )}

   //  FOLDER 3  -----------------------------------------------------------------------------------------------
   //  FOLDER 4  -----------------------------------------------------------------------------------------------
   //  END FOLDERS

   ACTIVATE DIALOG oDlg CENTERED

   oFont:End()
   close all

RETURN NIL



FUNCTION MARC_SETFILTER( oBrw ) // SETFILTER()?? INTERN COMMAND.

   LOCAL cFilter := ""
   LOCAL n, oCol, uVal, cType

   FOR n := 1 TO Len( oBrw:aCols )

      oCol  := oBrw:aCols[ n ]

      IF ! Empty( uVal := oCol:uBarGetVal )

         IF !Empty( cFilter )
            cFilter  += " .AND. "
         ENDIF

         cType    := ValType( uVal )

         DO CASE
         CASE cType == 'C'
            uVal     := Upper( AllTrim( uVal ) )
   // cFilter += '"' + uVal + '" $ UPPER( ' + FieldName( n ) + " )"
            cFilter += '"' + uVal + '" $ UPPER( ' + oCol:CExpr + " )"
         OTHERWISE
   // cFilter  += FieldName( n ) + " == " + cValToChar( uVal )
            cFilter  += oCol:cExpr + " == " + cValToChar( uVal )
         ENDCASE
      ENDIF

   NEXT
   // ******************************
   // /
   // msginfo(cFilter)
   // msgGet( "title", "message", @cFilter )

   IF Empty( cFilter )

      IF ! Empty( dbFilter() )
         dbClearFilter()
         oBrw:Refresh()
      ENDIF

   ELSE

      IF !( dbFilter() == cFilter )
         SET FILTER TO &cFilter
         GO TOP
         oBrw:Refresh()
      ENDIF

   ENDIF

   oBrw:SetFocus()

RETURN NIL

function getXbrowser(cData,oTarget)
  local aBrw:={}, aVeld:={}, aKop:={}, aSizes:={}, aFields:={}, oBrw
  local aBrwget:={}, aBrwedit:={}
  local aBrwCols:={}
  local cDbf, cZoek:="", cIndex
  Local nTop:=0, nLeft:=0, nBreed:=0, nHoogte:=0, cRelation:=""
  local cVelden:="", cHeaders:="", cSizes:="", cBrwget:="", cBrwedit:=""
  local cVeld, cFront, cBack, cExpres, lZoek:=.f.

  FIELD brwnaam,klant_nr,document   // Xbrowsers

  cData = upper(cData)
  //  Get data from dbf
  use brwsetup alias tempXb shared NEW
  tempxb->(dbsetorder("code"))

  select TempXB
  set filter to brwnaam = cData
  tempXB->(dbgotop())
  cDbf = alltrim(tempXb->database)
  cIndex = alltrim(tempXb->index)

  cMaster = alltrim(tempXb->master)
  nTop = tempXb->top
  nLeft = tempXb->left
  nBreed = tempXb->Breed
  nHoogte = tempXb->hoogte
  cRelation = alltrim(tempXb->relation)
  close tempXb
  //  Haal de detaildata
  use brwdetail alias tempXb shared NEW
  tempxb->(dbsetorder("code"))

  select tempXb
  set filter to brwnaam = cData
  tempXb->(dbgotop())
  do while !tempXb->(eof())
    if tempXb->sel_bar
      aadd(aBrwGet,alltrim(tempXb->brnaam))
    endif
    if tempXb->sel_edit
      aadd(aBrwEdit,alltrim(tempXb->brnaam))
    endif
    aadd(aVeld,alltrim(tempXb->veld))
    aadd(aKop,alltrim(tempXb->brnaam))
    aadd(aSizes,tempXb->size)
    tempXb->(dbskip())
  enddo
  close tempXb
  use (cdbf)
  select (cDbf)

  //  This data is comming from a dbf in real live )))
  //aadd(aBrwCols,{alltrim(tempXB->veld),alltrim(tempXb->colcond),alltrim(tempXb->colfront),alltrim(tempXb->colback)})
  aadd(aBrwCols,{"State","if(customer->state = 'IL',.T.,.F.)","0","8634760"})

  @ nTop,nLeft XBROWSE oBrw size nBreed,nHoogte PIXEL OF oTarget font oFont ;
      DATASOURCE cDbf ;
      COLUMNS aVeld ;
      HEADERS aKop ;
      COLSIZES aSizes ;
      AUTOSORT CELL LINES NOBORDER FOOTERS

   // Is nog een issue mee
   oBrw:CreateFromCode()

   StyleBrowse(oBrw, aBrwGet, aBrwEdit ,cData )
   /*                   */
   if len(aBrwCols) > 0
     for i = 1 to len(aBrwCols)
        cVeld = aBrwCols[i][1]
        cExpres = aBrwCols[i][2]
        cFront = val(aBrwCols[i][3])
        cBack = val(aBrwCols[i][4])
        cZoek = oBrw:&cVeld:value
        lZoek = &cExpres  // Execute expression with result .t. of .f.

        oBrw:&cVeld:bClrStd := { || if ( lZoek  , ;
        {nClrTxtBrw, cBack } ,;
        {nClrTxtBrw, If( oBrw:KeyNo() % 2 == 0, CLR_BROWSE2, CLR_BROWSE1 )}    )}
     next
   endif


   oBrw:refresh()

   oBrw:setfocus()

return oBrw

Static Function StyleBrowse( oBrwSel, aBarget, aEditget, cNaam )
   LOCAL hBmp    := ReadBitmap( 0, "bitmaps\search.bmp" )
   local cCol,cTemp
   DEFAULT aBarget:={}
   DEFAULT aEditget:={}
   DEFAULT cNaam:=""

   if lPijama  //  Make stripes in the browse
      oBrwSel:bClrStd = { || If( oBrwSel:KeyNo() % 2 == 0, ;
                            { If( ( oBrwSel:cAlias )->( Deleted() ), CLR_HRED, nClrTxtBrw ),;
                              CLR_BROWSE2 }, ;
                            { If( ( oBrwSel:cAlias )->( Deleted() ), CLR_HRED, nClrTxtBrw ),;
                              CLR_BROWSE1 } ) }
      oBrwSel:bClrSel = { || { If( ( oBrwSel:cAlias )->( Deleted() ), CLR_HRED, nClrBackBrw ),;
                              CLR_BROWSEROW } }
   else
      oBrwSel:bClrStd := { || { If( ( oBrwSel:cAlias )->( Deleted() ), CLR_HRED, nClrTxtBrw ),;
                          nClrBackBrw } }
      oBrwSel:bClrSel := { || { If( ( oBrwSel:cAlias )->( Deleted() ), CLR_HRED, nClrBackBrw ),;
                           MY_PAARS } }
   endif


   cClrBack     := Eval( oBrwSel:bClrSelFocus )[ 2 ]  //  I don't know what this is doing

   oBrwSel:SetChecks()
   //oBrwSel:bRClickHeaders := { || XbrColSelector( oBrwSel, cNaam ) }  // Kies welke velden tezien zijn

   WITH OBJECT oBrwSel
      :l2007               := .F.
      :lFooter          := .T.
      :bRecSelHeader    := {|| "Klant" }
      :bRecSelData      := {| o | o:KeyNo }
      :bRecSelFooter    := {| o | o:nLen }
      :oRecSelFont      := oFont  // optional
      :nRecSelWidth     := "99999" // required size

      :lColChangeNotify    := .T.
      :nMarqueeStyle       := MARQSTYLE_HIGHLROW

      :lHScroll      := .F.
      :lFullGrid           := .T.
      :lMultiSelect        := .T.
      :lRowDividerComplete := .T.
      :lColDividerComplete := .T.
      :nColDividerStyle    := LINESTYLE_LIGHTGRAY
      :nRowDividerStyle    := LINESTYLE_LIGHTGRAY
      :bClrSelFocus        := {|| { CLR_WHITE, CLR_BROWSECEL } } // CUANDO TIENE EL FOCUS
      :bClrRowFocus        := {|| { CLR_WHITE, CLR_BROWSEROW } }

      :nHeaderHeight       := 23
      :oHeaderFonts        := oBold
      :nHeadStrAligns      := AL_CENTER


      //:nFooterHeight     := oBrwSel:nHeaderHeight
      :nRowHeight          := oBrwSel:nHeaderHeight
      :nStretchCol         := NIL  // -2 // STRETCHCOL_WIDEST
      :nFreeze             := 1
      if lPijama
         :SetColor( CLR_BLACK, RGB( 232, 255, 232 ) ) // Pink
      else
         :SetColor( nClrTxtBrw, nClrBackBrw )
      endif
   END
   //  Toon de Bargetdata (Gets boven Bar)

   oBrwSel:lGetBar   := .T.  // Button to activate


   if len(aBarget)>0


      FOR EACH cCol in aBarget

         WITH OBJECT oBrwSel:oCol( cCol )

            :uBarGetVal    := uValBlank( :Value )

            :cBarGetPic    := :cEditPicture
            :bClrEdit      := {|| { CLR_BLACK, MY_LIGHTYELLOW } }

            :lBarGetOnKey := .T. // after having setfocus the oBrowse object, the end user can insert the characters directly into the get
            :cBarGetBmp := hBmp // this for show the Bitmap on the get
            :bBarGetAction := {|| ( oBrwSel:cAlias )->( MARC_SETFILTER( oBrwSel ) ) } // this for show the bitmap on the get and associated a action
// //         :bBarGetAction := {|| ( oBrwSel:cAlias )->( SETFILTER( oBrwSel ) ) } // this for show the bitmap on the get and associated a action

         END

      NEXT


   endif
   */


   if len(aEditget)>0
      //xbrowser(aEditget) title oBrwSel:cAlias()
      FOR EACH cCol in aEditget
         //msginfo(cCol+oBrwSel:cAlias(),"Info")
         WITH OBJECT oBrwSel:oCol( cCol )
            :nEditType     := EDIT_GET
            :bClrHeader    := {|| { CLR_WHITE, CLR_BROWSEINDEX } }
            //msginfo(cCol+oBrwSel:cAlias(),"Info Done")
         END
      NEXT
   endif

   */
Return nil


//  I use a database, but this is"
// Just for the forum so there is a sample dbf

function forumsetup()
local aFields:={}, aF2:={}
cFile = "brwsetup.dbf"
IF .NOT. FILE( cFile )

      aFields := { { "BRWNAAM", "C", 15, 0 },;
                   { "TOP", "N", 4, 0 },;
                   { "LEFT", "N", 4, 0 },;
                   { "BREED", "N", 4, 0 },;
                   { "HOOGTE", "N", 4, 0 },;
                   { "DATABASE", "C", 15, 0 },;
                   { "RELATION", "C", 200, 0 },;
                   { "INDEX", "C", 15, 0 },;
                   { "INFO", "C", 250, 0 },;
                   { "MASTER", "C", 10, 0 } }

  DbCreate( "brwsetup.dbf", aFields, "DBFCDX" )
  use brwsetup NEW VIA "DBFCDX"
  index on upper(brwnaam) tag code
  append blank
  brwsetup->brwnaam = "CUSTOMERS"
  brwsetup->DATABASE = "CUSTOMER"

  close brwsetup

endif

cFile = "brwdetail.dbf"
IF .NOT. FILE( cFile )

      aF2       := { { "VELD", "C", 15, 0 },;
                   { "BRNAAM", "C", 15, 0 },;
                   { "SIZE", "N", 3, 0 },;
                   { "SEL_BAR", "L", 1, 0 },;
                   { "SEL_EDIT", "L", 1, 0 },;
                   { "ORDER", "N", 4, 0 },;
                   { "TOP", "N", 4, 0 },;
                   { "LEFT", "N", 4, 0 },;
                   { "BREED", "N", 4, 0 },;
                   { "HOOGTE", "N", 4, 0 },;
                   { "BRWNAAM", "C", 20, 0 },;
                   { "PIC", "C", 20, 0 },;
                   { "ALIGN", "N", 1, 0 },;
                   { "DATABASE", "C", 15, 0 } }

  DbCreate( "brwdetail.dbf", aF2, "DBFCDX" )
  USE brwdetail NEW VIA "DBFCDX"
  INDEX ON upper(brwnaam)+str(order) TAG CODE
  append blank
  brwdetail->veld = "ID"
  brwdetail->brnaam = "ID"
  brwdetail->size = 100
  brwdetail->sel_bar = .T.
  brwdetail->sel_edit = .f.
  brwdetail->order = 1000
  brwdetail->brwnaam = "CUSTOMERS"

  append blank
  brwdetail->veld = "FIRST"
  brwdetail->brnaam = "First"
  brwdetail->size = 250
  brwdetail->sel_bar = .T.
  brwdetail->sel_edit = .T.
  brwdetail->order = 1010
  brwdetail->brwnaam = "CUSTOMERS"

  append blank
  brwdetail->veld = "LAST"
  brwdetail->brnaam = "Last"
  brwdetail->size = 250
  brwdetail->sel_bar = .T.
  brwdetail->sel_edit = .T.
  brwdetail->order = 1020
  brwdetail->brwnaam = "CUSTOMERS"

  append blank
  brwdetail->veld = "STATE"
  brwdetail->brnaam = "State"
  brwdetail->size = 100
  brwdetail->sel_bar = .T.
  brwdetail->sel_edit = .T.
  brwdetail->order = 1030
  brwdetail->brwnaam = "CUSTOMERS"


  close brwdetail
endif

return NIL


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

Re: Configurate xBrowser from dbf data issues

Postby Jimmy » Fri Feb 11, 2022 9:18 am

hi Marc,
Marc Venken wrote:
Code: Select all  Expand view
     for i = 1 to len(aBrwCols)
//  Rest code ...   
This code is working for 1 row, and then keeps the values the same for every folowing row, so the condition is not changing.

as i understand you want to build your Browse "in a Loop"
Code: Select all  Expand view
    for i = 1 to len(aBrwCols)

now you get result with "last Counter" Value for all

---

when use a Codeblock i do "create" it as String in a Function
Code: Select all  Expand view

   o:Property := DetachedLocal(i, aArray)

FUNCTION DetachedLocal(i, aArray)
RETURN &("{|| DoFunc(" + aArray[i] + " })
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Configurate xBrowser from dbf data issues

Postby hmpaquito » Fri Feb 11, 2022 9:46 am

Hi,

Authentic local detached like this:

Code: Select all  Expand view
FUNCTION DetachedLocal(i, aArray)
RETURN {|| DoFunc( aArray[i] ) }
 

regards
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Configurate xBrowser from dbf data issues

Postby Marc Venken » Fri Feb 11, 2022 11:48 am

Hey Guys,

You pointed me in the right direction ....

I now remember having issues with 'detached local' once or twice many years ago...

I will try to change my sample with the tips you gave me.

Is it so that in this loop all VAR's like :

cVeld = aBrwCols[i][1] // need to become something like

cVeld := DetachedLocal(i, aBrwCols,"V") // maybe a extra VAR "V" so the function knows it need to take the Veld als field Var
cExpres := DetachedLocal(i, aBrwCols,"E") // Expression

because the array aBrwCols is more dimensions



Code: Select all  Expand view

  if len(aBrwCols) > 0
     for i = 1 to len(aBrwCols)
        cVeld = aBrwCols[i][1]
        cExpres = aBrwCols[i][2]
        cFront = val(aBrwCols[i][3])
        cBack = val(aBrwCols[i][4])
        cZoek = oBrw:&cVeld:value
        lZoek = &cExpres  // Execute expression with result .t. of .f.

        oBrw:&cVeld:bClrStd := { || if ( lZoek  , ;
        {nClrTxtBrw, cBack } ,;
        {nClrTxtBrw, If( oBrw:KeyNo() % 2 == 0, CLR_BROWSE2, CLR_BROWSE1 )}    )}
     next
   endif

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 25 guests