FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Pasar de Browse de Hernan a xBrowse
Posts: 563
Joined: Sun Oct 09, 2005 07:23 PM
Pasar de Browse de Hernan a xBrowse
Posted: 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 (fw): Select all Collapse
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.
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Pasar de Browse de Hernan a xBrowse
Posted: 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
Posts: 563
Joined: Sun Oct 09, 2005 07:23 PM
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sat Mar 21, 2015 03: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

Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sat Mar 21, 2015 03:48 PM
Francisco J. Alegr铆a P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sun Mar 22, 2015 02:57 AM
Please start with this small sample as it is.
We used CUSTOMER.DBF in fwh\samples folder.
Code (fw): Select all Collapse
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: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
Posts: 563
Joined: Sun Oct 09, 2005 07:23 PM
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sun Mar 22, 2015 08: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 (fw): Select all Collapse
  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
         :={.f.}
         :CreateFromResource()
    end    
*/  
 
   REDEFINE METER ometer VAR mactual TOTAL mtotal ID 302 OF oDlg UPDATE

  ACTIVATE DIALOG oDlg NOWAIT
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sun Mar 22, 2015 09: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
Posts: 563
Joined: Sun Oct 09, 2005 07:23 PM
Re: Pasar de Browse de Hernan a xBrowse
Posted: 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.

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sun Mar 22, 2015 10:49 AM
This is the code
Code (fw): Select all Collapse
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
Posts: 563
Joined: Sun Oct 09, 2005 07:23 PM
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sun Mar 22, 2015 01:49 PM

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

Thanks a lot. :D

Posts: 563
Joined: Sun Oct 09, 2005 07:23 PM
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sun Mar 22, 2015 03: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. ...}

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Pasar de Browse de Hernan a xBrowse
Posted: Sun Mar 22, 2015 04: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

Continue the discussion