Page 1 of 1

convert from oldest Listbox to xbrowse

PostPosted: Fri Mar 22, 2019 8:17 am
by Silvio.Falconi
on old app I have a listbox have these commands

REDEFINE LISTBOX oBrd FIELDS (oDDom)->DomEnt HEADER "Domicilio" ;
ALIAS (oDDom)->(Alias()) ID 110 OF oDld

oBrd:bGoTop :={|| GoToTop(oDDom,cCli)}
oBrd:bGoBottom:={|| GoToBot(oDDom,cCli)}
oBrd:bSkip :={|n| MovePtr(oDDom,cCli,n)}


How I can converte ( the bold lines ) it into Xbrowse() ?

Re: convert from oldest Listbox to xbrowse

PostPosted: Fri Mar 22, 2019 9:21 am
by ukoenig
Silvio,

METHODS in xBrowse
just change the codeblocks to :

oBrd:GoTop()
oBrd:GoBottom()
oBrd:Skip( n )


regards
Uwe :D

Re: convert from oldest Listbox to xbrowse

PostPosted: Fri Mar 22, 2019 2:12 pm
by Silvio.Falconi
sorry but perhaps there is an error see cCli

Re: convert from oldest Listbox to xbrowse

PostPosted: Fri Mar 22, 2019 10:57 pm
by James Bott
You must be using a modified version of TListbox.

I searched TListbox, TControl, and TWindow for the variable bGoTop and it doesn't exist.

What are the functions GoToTop(), GoToBot(), and MovePtr() supposed to do?

Re: convert from oldest Listbox to xbrowse

PostPosted: Sat Mar 23, 2019 7:47 am
by Silvio.Falconi
WBROWSE OF HERNAN CECCARELLI Do you Know it ?

I have used this in the past in many applications before coming to the xbrowse
this source works well with Hernan's browse class (18/08/2004---Revision 17)

a part of oldest application
Code: Select all  Expand view


FUNCTION Otros_Dom(cCli)
   LOCAL oDld, oBrd, oDDom  , oDat[4]
   LOCAL oBtn[5], lNew, lCap, aDat[4]
   lNew:=lCap:=.F.
   oDDom:=Open_Dbf("DomEnt")
   (oDDom)->(DbSeek(cCli))
   DEFINE DIALOG oDld RESOURCE "Dlg_Dom" FONT oWnd:oFont
   REDEFINE LISTBOX oBrd FIELDS (oDDom)->DomEnt HEADER "Domicilio" ;
      ALIAS (oDDom)->(Alias()) ID 110 OF oDld
   oBrd:nClrForeHead:=CLR_BLUE
   oBrd:bGoTop   :={||  GoToTop(oDDom,cCli)}
   oBrd:bGoBottom:={||  GoToBot(oDDom,cCli)}
   oBrd:bSkip    :={|n| MovePtr(oDDom,cCli,n)}
   oBrd:bChange  :={|| Refr_Dom(oDDom,oDat,aDat)}
   REDEFINE GET oDat[1] VAR aDat[1] ID 201 OF oDld PICTURE "@!" WHEN lCap UPDATE VALID !Empty(aDat[1])
   REDEFINE GET oDat[2] VAR aDat[2] ID 202 OF oDld PICTURE "@!" WHEN lCap UPDATE
   REDEFINE GET oDat[3] VAR aDat[3] ID 203 OF oDld PICTURE "@!" WHEN lCap UPDATE
   REDEFINE GET oDat[4] VAR aDat[4] ID 204 OF oDld PICTURE "@!" WHEN lCap UPDATE
   REDEFINE BUTTON oBtn[1] ID 210 OF oDld ACTION RegD_Dom(.T.,lNew,oDat,aDat,oDDom,oBrd,@lCap,oBtn,cCli,oDld)         WHEN lCap
   REDEFINE BUTTON oBtn[2] ID 220 OF oDld ACTION RegD_Dom(.F.,lNew,oDat,aDat,oDDom,oBrd,@lCap,oBtn,cCli,oDld) CANCEL  WHEN lCap
   REDEFINE BUTTON oBtn[3] ID 120 OF oDld ACTION Edit_Dom(.T.,oDat,aDat,oDDom,oBrd,@lCap,@lNew,oBtn,oDld)
   REDEFINE BUTTON oBtn[4] ID 130 OF oDld ACTION Borra_Dom(oDDom,oBrd,cCli)
   REDEFINE BUTTON oBtn[5] ID 140 OF oDld ACTION Edit_Dom(.F.,oDat,aDat,oDDom,oBrd,@lCap,@lNew,oBtn,oDld)
   ACTIVATE DIALOG oDld ;
      ON INIT (oDat[1]:Hide(),oBtn[1]:Disable(),oBtn[2]:Disable());
      VALID (Close_Dbf("DomEnt",oDDom),.T.)
RETURN (NIL)
 



it use these lines
cCli is the account number of customer

oBrd:bGoTop :={|| GoToTop(oDDom,cCli)}
oBrd:bGoBottom:={|| GoToBot(oDDom,cCli)}
oBrd:bSkip :={|n| MovePtr(oDDom,cCli,n)}



Code: Select all  Expand view
FUNCTION GoToTop(cAlias,cKey)
   DbSelectArea(cAlias)
   (cAlias)->(DbSeek(cKey))
RETURN (NIL)

FUNCTION GoToBot(cAlias,cKey)
   LOCAL cTem:=STUFF(cKey,Len(cKey),1,Chr(Asc(Right(cKey,1))+1))
   DbSelectArea(cAlias)
   (cAlias)->(DbSeek(cTem,.T.))
   (cAlias)->(DbSkip(-1))
   IF &((cAlias)->(IndexKey(0)))=cKey
      (cAlias)->(DbSkip(0))
   ELSE
      (cAlias)->(DbSeek(cKey))
   ENDIF
RETURN (NIL)

FUNCTION MovePtr(cAlias,cKey,nReg)
   LOCAL nNext:=0
   DbSelectArea(cAlias)
   IF nReg=0 .OR. (cAlias)->(LastRec())=0 .OR. !(&((cAlias)->(IndexKey(0)))=cKey)
      (cAlias)->(DbSkip(0))
   ELSEIF nReg>0 .AND. (cAlias)->(RecNo())<>(cAlias)->(LastRec())+1
      DO WHILE nNext<=nReg .AND. !(cAlias)->(EoF()) .AND. &((cAlias)->(IndexKey(0)))=cKey
         (cAlias)->(DbSkip())
         nNext++
      ENDDO
      (cAlias)->(DbSkip(-1))
      nNext--
   ELSEIF nReg<0
      DO WHILE nNext>=nReg .AND. !(cAlias)->(BoF()) .AND. &((cAlias)->(IndexKey(0)))=cKey
         (cAlias)->(DbSkip(-1))
         nNext--
      ENDDO
      IF !(cAlias)->(BoF())
         (cAlias)->(DbSkip())
      ENDIF
      nNext++
   ENDIF
RETURN (nNext)
 

Re: convert from oldest Listbox to xbrowse

PostPosted: Sat Mar 23, 2019 4:21 pm
by James Bott
Silvio,

First set the index for the database object.

oClilents:setOrder("cli") // just an example

Then just do as Uwe says:

just change the codeblocks to :

oBrd:GoTop()
oBrd:GoBottom()
oBrd:Skip( n )

Re: convert from oldest Listbox to xbrowse

PostPosted: Sat Mar 23, 2019 4:48 pm
by Silvio.Falconi
not run ok

perhaps only but I made only a test

oGuests:= TGuests():New()
oGuests:Seek(cCli)
oGuests:OrdScope(0,cCli)
oGuests:OrdScope(1,cCli)

@2, 2 XBROWSE oBrowse OF oDglGuests SIZE 170,60 PIXEL;
COLUMNS "Cognome","Nome","TipoOspite";
HEADERS "Surname","Name","Type";
COLSIZES 100,100,90 ;
CELL LINES NOBORDER ;
DATASOURCE oGuests

Re: convert from oldest Listbox to xbrowse

PostPosted: Sat Mar 23, 2019 5:03 pm
by James Bott
not run ok


That is not much help. Exactly what is not OK?

You don't need to do a seek, and you may have to do a gotop() after setting the scope.

And your original message was about gotop() and gobottom(), not about scopes.

Re: convert from oldest Listbox to xbrowse

PostPosted: Sat Mar 23, 2019 6:05 pm
by Silvio.Falconi
I tried with scope simulating that codeblocks

Re: convert from oldest Listbox to xbrowse

PostPosted: Sat Mar 23, 2019 10:42 pm
by James Bott
So what is not working?

Re: convert from oldest Listbox to xbrowse

PostPosted: Mon Mar 25, 2019 9:52 am
by Silvio.Falconi
seem run ok