Tsbrowse to Xbrowse conversion of a function

Tsbrowse to Xbrowse conversion of a function

Postby Marc Venken » Thu Nov 23, 2017 11:10 pm

Hello,

In my conversion (16 to 32) , I used the folowing TS browse call a lot of times : (In a older NTX format for indexes)

REDEFINE BROWSE oLbxCol CELLED COLORS CLR_BLACK, CLR_WHITE ALIAS "kleuren" ID 3333 OF oDlg
NewLbx(oLbxcol,"ARTIKEL")

and this is the function, that I want to convert to Xbrowse. Can someone help me with this function?

I think that the indexes are not needed anymore, because Xbrowse allready know how to handle them?

Code: Select all  Expand view  RUN

function NewLbx(oLbx,cType)
   Local aTmp:={}
   cType = upper(alltrim(cType))
   DO case
         //          Titel        Field        Size   Edit   Indexen      Align 0-L,1-M,2-R,3-V
      CASE cType == "ARTIKEL"
         AADD(aTmp,{"Code"      ,"artikel_nr"  ,70   ,.F.  ,"artikel"     ,0  })
         AADD(aTmp,{"Lev.Code"  ,"ref_lev"     ,90   ,.F.  ,""            ,0  })
         AADD(aTmp,{"Benaming"  ,"Benaming"    ,400  ,.F.  ,"artnaam"     ,0  })
         AADD(aTmp,{"Mag"       ,"stonowtot"   ,50   ,.F.  ,""            ,2  })
         AADD(aTmp,{"Min"       ,"stomintot"   ,50   ,.F.  ,""            ,2  })
         AADD(aTmp,{"Teveel"    ,"stonowtot"   ,50   ,.F.  ,""            ,2  })
      CASE cType == "GOMPROSPECT"
         AADD(aTmp,{"Naam"      ,"naam"        ,120  ,.F.  ,"aboeknom"    ,0  })
         AADD(aTmp,{"Straat"    ,"straat"      ,100  ,.F.  ,"aboekstr"    ,0  })
         AADD(aTmp,{"Gemeente"  ,"Gemeente"    ,100  ,.F.  ,"aboekgem"    ,0  })
         AADD(aTmp,{"Volume"    ,"Grootte"     ,50   ,.F.  ,""            ,2  })
         AADD(aTmp,{"Telefoon"  ,"Tel1"        ,70   ,.T.  ,""            ,0  })
         AADD(aTmp,{"Activiteit","activiteit"  ,150  ,.T.  ,""            ,0  })
         AADD(aTmp,{"Zone"      ,"welk_it"     ,100  ,.T.  ,""            ,0  })
      OTHERWISE
         msginfo("Missing data","Programma fout")
         return
   Endcase
   nKoloms = len(aTmp)
   FOR I = 1  TO nKoloms
       ADD COLUMN TO oLbx ;
           MOVE DT_MOVE_RIGHT ;
           EDITABLE ;
           ALIGN DT_RIGHT,DT_CENTER,DT_RIGHT     // cells, header, footer

      oLbx:ACOLUMNS[I]:CHEADING :=        aTmp[i][1]
      oLbx:SetData(I, FieldWBlock(        aTmp[i][2], Select() ) )
      oLbx:SETCOLSIZE(I,                  aTmp[i][3])
      oLbx:aColumns[I]:lEdit :=           aTmp[i][4]
      oLbx:aColumns[I]:cOrder :=          aTmp[i][5]
      oLbx:SetAlign(I, 1,                 aTmp[I][6] )   // ( nCol, nLevel, nAlign )  nLevel 1 Cell, 2 Header, 3 Footer
      If aTmp[i][4] // Edit = .t.
        oLbx:SetColor( { 1,2 }, { CLR_BLACK, CLR_WIJZIG }, I )
      EndIF
   NEXT
   aTmp:={}
   oLbx:SetColor( { CLR_EDITF, CLR_EDITB }, { CLR_BLACK, CLR_YELLOW } )     // Editing
   oLbx:SetColor( { 14 }, { CLR_HRED, CLR_BLACK } )                        // Rood voor de actieve indexen
   oLbx:lNoHScroll := .T.                                                  // Geen H Scrollbar by default
return

 


I found this code of Mr. Rao, that is a function call to Xbrowse, but is not that easy to convert.

Code: Select all  Expand view  RUN

FUNCTION N21A_DEFCOLUMN(_oBR, D_COLUMNAS)

   LOCAL X:=0, _PIC, _COLOR:=""
   LOCAL _NCOLOR
   LOCAL D_COLSIZES := {}

   PRIVATE NCOLOR1 := CLR_WHITE, NCOLOR2 := CLR_HGRAY, NCOLOR3 := CLR_GRAY
   PRIVATE NCOLOR4 := CLR_YELLOW, NCOLOR5 := CLR_WHITE, NCOLOR6 := CLR_HGRAY
   PRIVATE NCOLOR7 := CLR_WHITE, NCOLOR8 := CLR_HGRAY, NCOLOR9 := CLR_GRAY

   D_COLSIZES:={}
   FOR X = 1 TO LEN(D_COLUMNAS)
      AADD(D_COLSIZES, IIF(D_COLUMNAS[X,3] < 3 , 40 , D_COLUMNAS[X,3] * 9 ) )
      _NCOLOR:= "NCOLOR" + ALLTRIM(IIF(X < 10, STR(X), "2"))
      _NCOLOR:= &_NCOLOR
      _PIC := IIF(D_COLUMNAS[X,2] = "N", REPLICATE("9",D_COLUMNAS[X,3]) + ".9999", REPLICATE("!",D_COLUMNAS[X,3]) )

      ADD COLUMN TO XBROWSE _oBR ;
      DATA FIELDWBLOCK( D_COLUMNAS[ x, 1 ], SELECT( "ST" ) ) ; //( N21A_FieldSetGetBlock( "ST", x ) ) ;
      HEADER D_COLUMNAS[X,1] SIZE (D_COLSIZES[X]) ;
      COLOR CLR_BLACK , _NCOLOR ;
      PICTURE _PIC ;
      EDITABLE
   NEXT

return nil
 




I only need this as a temporary solution, to get my 16 bit going in 32 bit. After this, for the important browses, I gone use Xbrowse on the best way, coded like Mr. Rao mostly suggest.

Thanks allready.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1449
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Tsbrowse to Xbrowse conversion of a function

Postby nageswaragunupudi » Fri Nov 24, 2017 3:00 pm

Now you are preparing an array like this
// Titel Field Size Edit Indexen Align 0-L,1-M,2-R,3-V

You can change it to prepare the same array in this way:

// Field, Title, Picture, Size
Eg:
AADD(aTmp,{ "artikel_nr", "Code", nil ,70 }

After preparing aTmp array:

@ r, c XBROWSER oBrw SIZE w,h PIXEL OF oWnd DATASOURCE <aliasname> COLUMNS aTmp

That's all
Regards

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

Re: Tsbrowse to Xbrowse conversion of a function

Postby Marc Venken » Fri Nov 24, 2017 3:16 pm

Thanks, but then I have to change all the array's (there are a lot of them) for each function call.

I prefer to only change the function.

While typing this, I realised that since I have the array build (the wrong way for XB) I can make a new array from the old.

I have to look into this closer.

By any change you have some other samples for calling Xbrowse from a function? During time, I thought to have seen some, but can't find them.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1449
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Tsbrowse to Xbrowse conversion of a function

Postby nageswaragunupudi » Fri Nov 24, 2017 3:29 pm

Please think again.
My suggestion is the simplest to implement
You will also find your code is reduced a lot
Regards

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

Re: Tsbrowse to Xbrowse conversion of a function

Postby Marc Venken » Fri Nov 24, 2017 4:08 pm

Mr. Rao

I Agree, I do use Xbrowse like this since I started with 32 bit:

Mostly good i think (just a sample)

But for the conversion I wanted to change the function so that I can have that program up and running as fast as possible.
Then, many changes will be done to get a real 32 bit feeling and for sure many Xbrowse's with all it's functionality , but I need it Up and running first from 16 to 32 Bit

I reconsider !

Thanks for your advice.

Code: Select all  Expand view  RUN

   aVelden :=  { ;
   { "ID"       , "Id"      ,nil,  90 }, ;
   { "orgfoto"  , "Foto"    ,nil,  60 }, ;
   { "naam"     , "Benaming",nil, 170 }, ;
   { "pagina"   , "Pag"     ,nil,  40 }, ;
   { "Online"   , "Onl"     ,nil,  30 }, ;
   { "reflev"   , "RefLev"  ,nil, 100 }, ;
   { "zoeken"   , "Zoekterm",nil, 100 }, ;
   { "fabrikan" , "Merk"    ,nil,  60 }, ;
   { "picfound" , "Pic"     ,nil,  30 }, ;
   { "kleur"    , "Kleur"   ,nil, 120 }, ;
   { "size"     , "Maat"    ,nil, 100 }, ;
   { "memotxt"  , "Memotxt" ,nil, 100 }, ;
   { "selected" , "Sel"     ,nil,  30 }, ;
   { "Prijs"    , "Prijs"   ,nil,  50 }, ;
   { "colaantal", "Col"     ,nil,  30 }, ;
   { "Wissen"   , "Wis"     ,nil,  30 } }

   @ 330,10 XBROWSE oBrw SIZE 1300,250 ;
      PIXEL OF oWnd font oFont3;
      DATASOURCE "nofoto" ;
      COLUMNS aVelden;
      AUTOSORT CELL LINES NOBORDER FASTEDIT

      oBrw:nEditTypes = EDIT_GET
      oBrw:SetChecks()
      // Color Header
      oBrw:memotxt:bClrHeader := { || { CLR_GREEN, 155 } }
      oBrw:kleur:bClrHeader := { || { CLR_GREEN, 155 } }
      oBrw:onl:bClrHeader := { || { CLR_GREEN, 155 } }
      oBrw:Sel:bClrHeader := { || { CLR_GREEN, 155 } }
      // Action to header
      oBrw:memotxt:bLClickHeader := { |r,c,f,oCol| FRichedit(oCol:Value),oBrw:refresh() }
      oBrw:kleur:bLClickHeader := { |r,c,f,oCol| edit_kleur(oCol:Value),oBrw:refresh() }
      oBrw:onl:bLClickHeader := { |r,c,f,oCol| mark_online(oCol:Value),oBrw:gotop(),oBrw:setfocus(),oBrw:refresh() }
      oBrw:Sel:bLClickHeader := { |r,c,f,oCol| mark_selection(oCol:Value),oBrw:refresh() }

   WITH OBJECT oBrw
//      :lEditMode := .T.
      :lFooter          := .t.
      :bRecSelHeader    := { || "RowNo" }
      :bRecSelData      := { |o| o:KeyNo }
      :bRecSelFooter    := { |o| o:nLen }
      :oRecSelFont      := oFont3  // optional
      :nRecSelWidth     := "99999" // required size
      :nStretchCol      := 1  // stretch 1 kolom to einde browse

      :bChange    := { || nSecs := SECONDS() }
      :bKeyDown   := { |nKey| If( nKey == VK_DELETE, (oBrw:cAlias)->( BrwDelselect( oBrw ) ), nil ) }

      :lMultiSelect     := .T.

      oBrw:kleur:bToolTip :=  { | oBrw,r,c,f,oMouseCol,nMouseRow| MyColToolTip( oBrw,r,c,f,oMouseCol,nMouseRow ) }
      oBrw:memotxt:bToolTip :=  { | oBrw,r,c,f,oMouseCol,nMouseRow| MyColToolTip( oBrw,r,c,f,oMouseCol,nMouseRow ) }

      WITH OBJECT:kleur
         :nEditType     := EDIT_GET_BUTTON
         :bClrSel          := { || { CLR_BLACK, CLR_HGRAY }}
         :bEditBlock    := { |r,c,oCol| fotoSelect( oCol:Value ) }
      // :bOnChange     := { |oCol,uOldVal| oBrw:kleur:VarPut( tempfoto->foto ) }
      ENDWITH

      WITH OBJECT :oCol( 1 )
         :nEditType     := EDIT_GET_BUTTON
         :bClrSel          := { || { CLR_BLACK, CLR_YELLOW }}
         :bEditBlock    := { |r,c,oCol| LookupArt( oCol:Value ) }
      ENDWITH

      WITH OBJECT :oCol( 2 )
         :nEditType     := EDIT_GET_BUTTON
         :bClrSel          := { || { CLR_BLACK, CLR_YELLOW }}
         :bEditBlock    := { |r,c,oCol| LookupPic( oCol:Value ) }
      ENDWITH

      WITH OBJECT:memotxt
         :nEditType     := EDIT_GET
         :bClrSel          := { || { CLR_BLACK, CLR_YELLOW }}
         :bEditBlock    := { |r,c,oCol| edit_memo( oCol:Value ) }
      ENDWITH
      :bClrEdits        := { || { CLR_BLACK, CLR_YELLOW }}
      :nMarqueeStyle    := MARQSTYLE_HIGHLROWMS
      :bClrRowFocus     := { || { CLR_BLACK, RGB(185,220,255) } }

      :CreateFromCode()
   END
   oBrw:bRClicked     := { |r,c,f,oStru| msginfo(nofoto->ID),oClp:SetText(alltrim(nofoto->ID)) }
   oBrw:bGotFocus := {|| updatescreen() }
   oBrw:aCols[7]:bClrStd := { || IF( !nofoto->picfound , { CLR_BLACK,CLR_HRED } , { CLR_HRED,CLR_WHITE } ) }
   oBrw:aCols[3]:bClrStd := { || IF( nofoto->wissen , { CLR_HRED,CLR_WHITE } , { CLR_BLACK,CLR_WHITE } ) }

 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1449
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Tsbrowse to Xbrowse conversion of a function

Postby nageswaragunupudi » Fri Nov 24, 2017 4:19 pm

Good.

It is better if you recast the arrays like this.

In case you do not have time even to recast the arrays you can use the existing arrays ( without change ) like this:

Code: Select all  Expand view  RUN


// aTmp is the array as defined in your old program

aTmp := ArrTranspose( aTmp )  // This is important

@ r,c XBROWSE <clauses> ;
   COLUMNS aTmp[ 2 ] HEADERS aTmp[ 1 ] COLSIZES aTmp[ 3 ] ;
   <otherClauses>
 
Regards

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 31 guests