Page 1 of 1

Mr. Rao, more about xBrowse

Posted: Mon Aug 21, 2023 4:45 pm
by Armando
Mr. Rao:

I have the following code, I need the same code for all the columns of the browse, something like :nEditTypes := 1, I know that I can repeat it as many columns as the browse has, the problem is that I don't know how many columns the browse has.

Code: Select all | Expand

            WITH OBJECT :aCols[03]
               :bOnPreEdit := { | oCol, xVal, nKey | IIF(nSaldo <= 0,MsgStop("No hay más autobuses disponibles !",oApp:cAplicacion),)}
               :bOnChange  := { | oCol, uOldVal| VerSaldo(uOldVal) } 
               :bEditValid := { | oGet | Valida(oGet:VarGet())}         
            END
 
I am building the browse with the code AUTOCOLS


Thank you for your kind help

Best regards

Re: Mr. Rao, more about xBrowse

Posted: Mon Aug 21, 2023 7:20 pm
by cmsoft
Podria ser algo asi:

Code: Select all | Expand

for each oCol in :aCols
      oCol:bOnPreEdit := { | oCol, xVal, nKey | IIF(nSaldo <= 0,MsgStop("No hay más autobuses disponibles !",oApp:cAplicacion),)}
      oCol:bOnChange  := { | oCol, uOldVal| VerSaldo(uOldVal) }
      oCol:bEditValid := { | oGet | Valida(oGet:VarGet())}
next oCol

Re: Mr. Rao, more about xBrowse

Posted: Mon Aug 21, 2023 8:12 pm
by Armando
Cesar:

Gracias por la idea, pero me tira error, no reconoce oCol

Saludos

Re: Mr. Rao, more about xBrowse

Posted: Mon Aug 21, 2023 10:17 pm
by cmsoft
Fijate si algo asi es la idea
Tenias razon, lo otro daba error

Code: Select all | Expand

#include "Fivewin.ch"
#include "xbrowse.ch"
static nSaldo, oSay 
FUNCTION cmsoft()
LOCAL oDlg1, oBrwTmp, aCols, oCol, nFilas := 3, nColumnas := 3, i, j 
nSaldo := 10000
MsgGet("Filas","Ingrese filas",@nFilas)
MsgGet("Columnas","Ingrese columnas",@nColumnas)
aCols := ARRAY(nFilas,nColumnas)
FOR i := 1 to nFilas 
    for j := 1 to nColumnas 
        aCols [i,j] := 0
    next j
next i
DEFINE DIALOG oDlg1 TITLE "Edicion" SIZE 700,700 PIXEL TRUEPIXEL RESIZABLE
   @ 20, 20 XBROWSE oBrwTmp SIZE -20,-20 pixel OF oDlg1 ;
      CELL LINES NOBORDER
   WITH OBJECT oBrwTmp
      :SetArray(aCols)
      AEval( :aCols, ;
         { |o| (o:bOnPreEdit := { | o, xVal, nKey | IIF(nSaldo <= 0,MsgStop("No hay más autobuses disponibles !","Atencion"),)}), ;
               (o:bOnChange  := { | o, uOldVal| VerSaldo(uOldVal) }),;
               (o:bEditValid := { | oGet | Valida(oGet:VarGet())}),;
               (o:nEditType := EDIT_GET) })


      /*for each oCol in :aCols
            oCol:bOnPreEdit := { | oCol, xVal, nKey | IIF(nSaldo <= 0,MsgStop("No hay más autobuses disponibles !","Atencion"),)}
            oCol:bOnChange  := { | oCol, uOldVal| VerSaldo(uOldVal) }
            oCol:bEditValid := { | oGet | Valida(oGet:VarGet())}
            oCol:nEditType := EDIT_GET 
      next oCol      */
      :CreateFromCode()
   END
@ 0,0 Say "Saldo" GET oSay VAR nSaldo  PIXEL   OF oDlg1 READONLY
ACTIVATE DIALOG oDlg1 CENTERED 
RETURN nil

static function VerSaldo(n)
nSaldo := nSaldo + n
oSay:Refresh()
return nil 

static function valida(n)
IF (nSaldo - n) <= 0 
   MsgStop("El importe super el saldo")
   RETURN .f.
ENDIF 
nsaldo := nSaldo - n
oSay:Refresh()
return .t.

Re: Mr. Rao, more about xBrowse

Posted: Mon Aug 21, 2023 11:01 pm
by Armando
César:

Gracias, pruebo y aviso.

Saludos

Re: Mr. Rao, more about xBrowse

Posted: Tue Aug 22, 2023 12:40 am
by nageswaragunupudi
cmsoft wrote:Podria ser algo asi:

Code: Select all | Expand

for each oCol in :aCols
      oCol:bOnPreEdit := { | oCol, xVal, nKey | IIF(nSaldo <= 0,MsgStop("No hay más autobuses disponibles !",oApp:cAplicacion),)}
      oCol:bOnChange  := { | oCol, uOldVal| VerSaldo(uOldVal) }
      oCol:bEditValid := { | oGet | Valida(oGet:VarGet())}
next oCol
XBrowse provides a much easier way.
No need for using "for each oCol in :aCols" or "AEval( :aCols.", etc.

Code: Select all | Expand

WITH OBJECT oBrw
      :bOnPreEdits := { | oCol, xVal, nKey | IIF(nSaldo <= 0,MsgStop("No hay más autobuses disponibles !",oApp:cAplicacion),)}
      :bOnChanges  := { | oCol, uOldVal| VerSaldo(uOldVal) }
      :bEditValids := { | oGet | Valida(oGet:VarGet())}
END
Explanation:
If you want to set any data of each column (for example "nEditType" ), instead of setting oCol:nEditType of each every column, you can set oBrw:nEditTypes := n ( nEditType _+ "s" ) i.e., use "plural"

Re: Mr. Rao, more about xBrowse

Posted: Tue Aug 22, 2023 1:27 am
by Armando
Mr. Rao (Master)

It works soo fine.

Thanks so much.

Best regards

Re: Mr. Rao, more about xBrowse

Posted: Tue Aug 22, 2023 12:17 pm
by cmsoft
Muchas gracias por la aclaración, mucho mas facil así. Cada dia me sorprendo mas del poder de xbrowse!!

Re: Mr. Rao, more about xBrowse

Posted: Tue Aug 22, 2023 8:58 pm
by nageswaragunupudi
Explanation:
If you want to set any data of each column (for example "nEditType" ), instead of setting oCol:nEditType of each every column, you can set oBrw:nEditTypes := n ( nEditType _+ "s" ) i.e., use "plural"
If we want to set the same value for any DATA of every column, we use

Code: Select all | Expand

oBrw:datas := uValue
If we want to set different values like [ a, b, c, d, ... } to each column in the creation order we use

Code: Select all | Expand

oBrw:datas := { a, b, c, .... }
Examples:

Code: Select all | Expand

oBrw:nEditTypes := EDIT_GET
oBrw:cSortOrders := { "ID","FIRST","LAST", ... }

Re: Mr. Rao, more about xBrowse

Posted: Tue Aug 22, 2023 9:29 pm
by Armando
Mr. Rao:

Thanks so much.

With best regards

Re: Mr. Rao, more about xBrowse

Posted: Wed Aug 23, 2023 7:14 am
by Marc Venken
nageswaragunupudi wrote:
cmsoft wrote: Explanation:
If you want to set any data of each column (for example "nEditType" ), instead of setting oCol:nEditType of each every column, you can set oBrw:nEditTypes := n ( nEditType _+ "s" ) i.e., use "plural"
Out of interest : In the source class, i don't see these data as plural ? how does Xbrowse know them ?

like :

oBrw:nEditTypes := EDIT_GET

Re: Mr. Rao, more about xBrowse

Posted: Wed Aug 23, 2023 7:26 am
by nageswaragunupudi
XBrowse is not that simple class.
Well all this is handled in the Error Handler.

There is no DATA nEditTypes in XBrowse, so this message goes to error handler.
There it checks if there is any data of a Column class with that name without trailing "s"
If exists then the rest of the logic is simple.