Page 1 of 1

xBrowse and bClrStd

Posted: Mon Sep 07, 2020 10:33 am
by Maurizio
Good morning RAO

I have an array of colors and would like to apply it to the columns

this example works

Code: Select all

#include "fivewin.ch"
#include "xbrowse.ch"

function main()

  local oDlg, oBrw
  local aData    := { { "One", "Two" ,"_111"}, { "Three", "Four","_222" }, { "Five", "Six","_333" }  }

  DEFINE DIALOG oDlg SIZE 300,200 PIXEL TITLE FWVERSION

   @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
         DATASOURCE aData AUTOCOLS ;
         CELL LINES NOBORDER

   WITH OBJECT oBrw
      :bClrStd    := { || { CLR_BLACK, CLR_WHITE } }
      :aCols[ 1 ]:bClrStd  := { || { CLR_BLACK, CLR_HGREEN } }
      :aCols[ 2 ]:bClrStd  := { || { CLR_BLACK, CLR_RED} }
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED

return nil
if I change with array ,it doesn't work

Code: Select all

function main()

  local oDlg, oBrw
  local aData    := { { "One", "Two" ,"_111"}, { "Three", "Four","_222" }, { "Five", "Six","_333" }  }

  lOCAL aColor  := {CLR_HGREEN , CLR_RED}

  DEFINE DIALOG oDlg SIZE 300,200 PIXEL TITLE FWVERSION

   @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
         DATASOURCE aData AUTOCOLS ;
         CELL LINES NOBORDER

   WITH OBJECT oBrw
      :bClrStd    := { || { CLR_BLACK, CLR_WHITE } }
      FOR n := 1 to 2
          :aCols[ n ]:bClrStd  := { || { CLR_BLACK,:aCols[n]  } }
      NEXT 
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED

return nil
Maurizio

Re: xBrowse and bClrStd

Posted: Mon Sep 07, 2020 11:06 am
by nageswaragunupudi
Whatever be the context, you should not use index variable inside a codeblock created inside the loop.
This is one fundamental rule we need to keep in mind since the clipper days.

Re: xBrowse and bClrStd

Posted: Mon Sep 07, 2020 12:32 pm
by Maurizio
thanks RAO
there is workaraund for works with an array of color ?
I need to parameterize the colors of the columns .

Maurizio

Re: xBrowse and bClrStd

Posted: Mon Sep 07, 2020 12:59 pm
by Enrico Maria Giordano
At least, this is an error:

Code: Select all

:aCols[ n ]:bClrStd  := { || { CLR_BLACK,:aCols[n]  } }
Replace it with this other:

Code: Select all

:aCols[ n ]:bClrStd  := { || { CLR_BLACK,oBrw:aCols[n]  } }
EMG

Re: xBrowse and bClrStd

Posted: Mon Sep 07, 2020 1:09 pm
by Maurizio
Sorry Enrico I copied the wrong example,

Code: Select all

function main()

  local oDlg, oBrw
  local aData    := { { "One", "Two" ,"_111"}, { "Three", "Four","_222" }, { "Five", "Six","_333" }  }

  lOCAL aColor  := {CLR_HGREEN , CLR_RED} ,nColore

  DEFINE DIALOG oDlg SIZE 300,200 PIXEL TITLE FWVERSION

   @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
         DATASOURCE aData AUTOCOLS ;
         CELL LINES NOBORDER

   WITH OBJECT oBrw
      :bClrStd    := { || { CLR_BLACK, CLR_WHITE } }
          
      FOR n := 1 to 2
          :aCols[ n ]:bClrStd  :=   { || { CLR_BLACK,aColor[n]  } }
      NEXT 
     :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED

return nil

Re: xBrowse and bClrStd

Posted: Mon Sep 07, 2020 1:16 pm
by Enrico Maria Giordano
Try this:

Code: Select all

#include "Fivewin.ch"


function main()

  local oDlg, oBrw
  local aData    := { { "One", "Two" ,"_111"}, { "Three", "Four","_222" }, { "Five", "Six","_333" }  }

  lOCAL aColor  := {CLR_HGREEN , CLR_RED}

  local n

  DEFINE DIALOG oDlg SIZE 300,200 PIXEL TITLE FWVERSION

   @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
         DATASOURCE aData AUTOCOLS ;
         CELL LINES NOBORDER

   WITH OBJECT oBrw
      :bClrStd    := { || { CLR_BLACK, CLR_WHITE } }
         
      FOR n := 1 to 2
          :aCols[ n ]:bClrStd  := MAKEBLOCK( aColor, n )
      NEXT
     :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED

return nil


STATIC FUNCTION MAKEBLOCK( aColor, n )

    RETURN { || { CLR_BLACK,aColor[n]  } }
EMG

Re: xBrowse and bClrStd

Posted: Mon Sep 07, 2020 1:30 pm
by Maurizio
Grazie Enrico ,

works as I wanted :D

Maurizio