Pasar de Browse de Hernan a xBrowse

Pasar de Browse de Hernan a xBrowse

Postby Verhoven » Sat Mar 21, 2015 11:12 am

Estoy planteándome cambiar todos los Browse de Hernan a xBrowse.
Viendo los ejemplos, me encuentro con una llamada del tipo
Code: Select all  Expand view
CreateFromCode()
que no entiendo muy bien qué utilidad tiene.
Si alguien tiene un rato le agradecería una mano con esta clase o si hay algún manual, pues he echado una ojeada a la clase xBrowse y tiene más de 13000 líneas de código...
En fin, no se si el cambio a ser un poco arriesgado para aplicaciones en producción.
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: Pasar de Browse de Hernan a xBrowse

Postby cnavarro » Sat Mar 21, 2015 12:08 pm

Hay muchos ejemplos en el foro, pero es sencillo:
Tu defines el XBrowse y sus propiedades y, para que se ejecute has de usar:
- CreateFromCode() si es definido por el usuario
- CreateFromResource() si lo has definido en un RC
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6504
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Pasar de Browse de Hernan a xBrowse

Postby Verhoven » Sat Mar 21, 2015 3:34 pm

He conseguido montar varios de los browse.
No me ha hecho falta usa esos métodos que me pones. Con un simple REDEFINE XBROWSE ... en vez REDEFINE LISTBOX los crea.
Pero estoy atascado en uno en el que necesito editar uno solo de los campos de una tabla y poder validar la entrada antes de grabar el valor el dbf y actualizar la visulaización del xBrowse.
No encuentro la manera de hacerlo por más que repaso los testxbr... del fwh
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: Pasar de Browse de Hernan a xBrowse

Postby FranciscoA » Sat Mar 21, 2015 3:48 pm

Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2114
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Pasar de Browse de Hernan a xBrowse

Postby nageswaragunupudi » Sun Mar 22, 2015 2:57 am

Please start with this small sample as it is.
We used CUSTOMER.DBF in fwh\samples folder.
Code: Select all  Expand view
function testxbr()

   local oDlg, oFont, oBrw

   USE C:\\FWH\\SAMPLES\\CUSTOMER NEW ALIAS CUST SHARED

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 700,400 PIXEL FONT oFont

   @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
      DATASOURCE "CUST" ;
      COLUMNS "First", "City", "Age", "Salary" ;
      CELL LINES NOBORDER ;
      FASTEDIT  // FASTEDI enables edit on pressing any key

   WITH OBJECT oBrw
      :nEditTypes    := EDIT_GET  // We enable editing of all cells
      //
      :CreateFromCode() // Tells xbrowse we finished our coding
   END

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

   CLOSE CUST

return nil
 

Please use COLUMNS clause to specify the field names to display and edit. This enables XBrowse to internally get ready for edit, save and display the field contents. Important: Please do not use FIELDS clause.

By default, xbrowse does not allow the user to edit. We need to set the column object's DATA nEditType to EDIT_GET, etc. to enable edit. oBrw:nEditTypes := EDIT_GET is a short cut for assigining each oCol:nEditType := EDIT_GET.

When FASTEDIT is used, pressing any key invokes inline edit. If not, the user can start edit first by pressing ENTER key.

The entire process of editing the cell, locking/unlocking of the table, saving data and refreshing the browse is all automatic.

After testing this sample, you may then extend this sample to your DBFs and specifying your columns.

WHEN:
For each column, we can also specify a when condition and valid check:

oBrw:aCols[ 4 ]:bEditWhen := { || oBrw:aCols[ 3 ]:Value > 0 }
This is same as:
oBrw:Salary:bEditWhen := { || oBrw:Age:Value > 0 }

VALID:
oBrw:Age:bEditValid := { |oGet| oGet:Value() > 0 }
Note: bEditWhen and bEditValid should not contain any Screen I/O.
Regards

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

Re: Pasar de Browse de Hernan a xBrowse

Postby Verhoven » Sun Mar 22, 2015 8:38 am

Thanks for your help. I was using clause FIELDS in translations to xBrowse, and even they works I will change all of then to the new DATASOURCE.

But I need help with the translation to xBrowse of the next simple code:

Code: Select all  Expand view
 DEFINE DIALOG oDlg RESOURCE "Arranque" OF oPadre;
         FONT oFontDoble TITLE 'Arranque del SISTEMA'

/* THIS CODE WORKS FINE */
   REDEFINE LISTBOX oBrw FIELDS aList[oBrw:nAt];
             HEAD '* Lista de comprobación *'                        ;
             FIELDSIZES 200  ;
             ID 102 OF oDlg          ;
             COLOR clrLtrBrow,clrFonBrow ;  
             UPDATE
   oBrw:SetArray( aList )
   WITH OBJECT oBrw
      :nLineStyle:= 0
   end

 /* BUT NEXT CODE FAILS:
    REDEFINE XBROWSE oBrw DATASOURCE aList
             HEAD '* Lista de comprobación *' ;
             COLSIZES 200;
             ID 102 OF oDlg ;
             COLOR clrLtrBrow,clrFonBrow ;
             UPDATE
    WITH OBJECT oBrw
         :nRowDividerStyle:= LINESTYLE_LIGHTGRAY
         :nColDividerStyle:= LINESTYLE_LIGHTGRAY
         :aJustify:={.f.}
         :CreateFromResource()
    end    
*/
 
 
   REDEFINE METER ometer VAR mactual TOTAL mtotal ID 302 OF oDlg UPDATE

  ACTIVATE DIALOG oDlg NOWAIT
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: Pasar de Browse de Hernan a xBrowse

Postby cnavarro » Sun Mar 22, 2015 9:32 am

Quizas cambiando la variable oBrw del segundo XBrowse
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6504
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Pasar de Browse de Hernan a xBrowse

Postby Verhoven » Sun Mar 22, 2015 10:26 am

No está cambiada. El error que da es que no puede crear el diálogo. El fallo lo da al activar el dialogo.
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: Pasar de Browse de Hernan a xBrowse

Postby nageswaragunupudi » Sun Mar 22, 2015 10:49 am

This is the code
Code: Select all  Expand view
DEFINE DIALOG oDlg RESOURCE "Arranque" OF oPadre;
         FONT oFontDoble TITLE 'Arranque del SISTEMA'

   REDEFINE XBROWSE ID 102 OF oDlg ;
      DATASOURCE aList AUTOCOLS ;
      HEADERS '* Lista de comprobación *' ;
      COLOR clrLtrBrow,clrFonBrow ;  
      UPDATE

   REDEFINE METER ometer VAR mactual TOTAL mtotal ID 302 OF oDlg UPDATE

ACTIVATE DIALOG oDlg NOWAIT
 

Notes:
1) You change name of ID 102 in the RC file as "TXBrowse"
2) When you create xbrowse with REDEFINE COMMAND you should not again use oBrw:CreateFromResource( ID ). This method call is aleady incloded in the command.

Please try the code as it is and let us know the result.
Regards

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

Re: Pasar de Browse de Hernan a xBrowse

Postby Verhoven » Sun Mar 22, 2015 1:49 pm

Now it is Ok. The problem was inside de .RC: the TWBrowse must chenge to TXBrowse.

Thanks a lot. :D
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: Pasar de Browse de Hernan a xBrowse

Postby Verhoven » Sun Mar 22, 2015 3:11 pm

¿Cómo hago para alinear los textos de las cabeceras igual que el contenido de sus correspondientes columnas?
Para las columnas uso :aJustify:={.t.,.f.,2,.t. ...}
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: Pasar de Browse de Hernan a xBrowse

Postby nageswaragunupudi » Sun Mar 22, 2015 4:49 pm

Normally we do not need to specify alignments, pictures, etc to xbrowse. Unlike other browses, XBrowse by default selects appropriate alignment depending on the Data Type of the column.

By default, numbers and dates are right aligned and all other types like character, etc. are left aligned, for data, header and footers.

We need to specify alignment only when we need to use a different alignment other than the default.

oBrw:aJustiy was created for compatibility with wbrowse, but we rather specify the alignment directly in the XBROWSE command.

@ r, c XBROWSE oBrw ...................................
JUSTIFY .f., .t., AL_CENTER, nil, .......

If required, we can specify justifications for each column.
oCol:nHeadStrAlign := AL_LEFT / AL_CENTER / AL_RIGHT
oCol:nDataStrAlign := ...
oCol:nFootStrAlign

Instead of specifying justification for each column separately we can use short cut

oBrw:nHeadStrAligns := AL_CENTER // Aligns all headers centered
oBrw:nHeadStrAligns := { .t., .f., AL_RIGHT, ....etc } // Aligns different column headers as in array

My advice:
At first do not specify alignments and pictures.
See the browse.
When you want to override the default behavior, then only assign where you want a non-default behavior.
Regards

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


Return to FiveWin para Harbour/xHarbour

Who is online

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