Page 1 of 1
Pasar de Browse de Hernan a xBrowse
Posted: Sat Mar 21, 2015 11:12 am
by Verhoven
Estoy planteándome cambiar todos los Browse de Hernan a xBrowse.
Viendo los ejemplos, me encuentro con una llamada del tipo
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.
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sat Mar 21, 2015 12:08 pm
by cnavarro
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
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sat Mar 21, 2015 3:34 pm
by Verhoven
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 _ 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
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sat Mar 21, 2015 3:48 pm
by FranciscoA
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sun Mar 22, 2015 2:57 am
by nageswaragunupudi
Please start with this small sample as it is.
We used CUSTOMER.DBF in fwh\samples folder.
Code: Select all
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.
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sun Mar 22, 2015 8:38 am
by Verhoven
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
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
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sun Mar 22, 2015 9:32 am
by cnavarro
Quizas cambiando la variable oBrw del segundo XBrowse
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sun Mar 22, 2015 10:26 am
by Verhoven
No está cambiada. El error que da es que no puede crear el diálogo. El fallo lo da al activar el dialogo.
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sun Mar 22, 2015 10:49 am
by nageswaragunupudi
This is the code
Code: Select all
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.
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sun Mar 22, 2015 1:49 pm
by Verhoven
Now it is Ok. The problem was inside de .RC: the TWBrowse must chenge to TXBrowse.
Thanks a lot.
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sun Mar 22, 2015 3:11 pm
by Verhoven
¿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. ...}
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sun Mar 22, 2015 4:49 pm
by nageswaragunupudi
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.