browse arrays using xbrowse

browse arrays using xbrowse

Postby ellano » Fri Sep 25, 2009 4:46 pm

To all:

Although there are zillions of examples out ther using listbox (aka Browse):
oBrw1:bGoTop = { || nItem := 1 }
oBrw1:bGoBottom = { || nItem := Eval( oBrw1:bLogicLen ) }
oBrw1:bSkip = { | nWant, nOld | nOld := nItem, nItem += nWant,;
nItem := Max( 1, Min( nItem, Eval( oBrw1:bLogicLen ) ) ),;
nItem - nOld }
oBrw1:bLogicLen = { || LEN(aRange)

how do you adapt them to xBrowse? I've tried
nOld:=0
oBrw[1]:SetArray( aMyArray, .t. )
oBrw[1]:bGoTop = { || nItem := 1 }
oBrw[1]:bGoBottom = { || nItem := lenMyArray }
oBrw[1]:bSkip = { | nWant | (nOld := nItem, nItem = nItem + nWant,;
nItem := Max( 1, Min( nItem, lenMyArray ) ), nItem - nOld ) }
oBrw[2]:REFRESH(.t.)
oBrw[1]:CreateFromCode()
But it only displays the first element.

Emiliano Llano
ellano
 
Posts: 107
Joined: Tue Sep 15, 2009 7:52 am

Re: browse arrays using xbrowse

Postby James Bott » Fri Sep 25, 2009 10:43 pm

Try not setting all the codeblocks--those are set by SetArray().

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: browse arrays using xbrowse

Postby ellano » Sat Sep 26, 2009 6:47 am

Thanks James.

That helped a bit, but:
a) the first browse (obrw[1] obeys the mouse clicks but not the keyboard :shock: and
b) the two xbrowse(s) freezes when returning from another xbrowse like so:
oBrw[1]:bChange := { || browse2(which,oRange,@oBrw) }
oBrw[2]:nClrText = { || IIF(client->rent_sale,CLR_HBLUE,CLR_BLACK) }
oBrw[2]:nClrForeFocus = { || IIF(client->rent_sale,CLR_HGREEN,CLR_WHITE) }
oBrw[1]:SetArray( aRangos, .t. )
oBrw[2]:bLDblClick := {|| show_client(which,oBrw[1]:nRowSel,oRange,@oBrw,aVar), ;
oBrw[1]:SetFocus(), oBrw[2]:REFRESH(.t.), oBrw[1]:REFRESH(.t.) } //freeze on return :(

oBrw[1]:CreateFromCode()
oBrw[2]:CreateFromCode()

Emiliano Llano
ellano
 
Posts: 107
Joined: Tue Sep 15, 2009 7:52 am

Re: browse arrays using xbrowse

Postby ellano » Sat Sep 26, 2009 11:17 am

Ok. Here is the final code when doing a synchronized search in an array and database (now fully working)

Clean_Areas()
SELECT sales
SET ORDER TO TAG "price"
DBSETFILTER( &( "{|| sales->tip_ofer="+which+" .AND. sales->price_range=1 }"))
DBGOTOP()
DEFINE FONT oTipograf NAME "Arial" SIZE 0,-10
DEFINE DIALOG oRanges FROM 1,3 TO 19,81 TITLE letr FONT oTipograf
@ 1,.3 XBROWSE oBrw[1] ;
HEADER "Limit" ;
ARRAY aRanges ;
SIZE 60,120 of oRanges COLOR RGB(0,0,0),RGB(224,254,253) UPDATE

@ 1,8.75 XBROWSE oBrw[2] ;
FIELDS sales->code, IIF(sales->clasf>0,aVar[3][sales->clasf]," "), ;
IIF(sales->Type>0,aVar[6][sales->type]," "), ;
ALLTRIM(STR(sales->number,3,0)+' '+sales->street), sales->city ;
ALIAS "Sales" ;
HEADERS "Code","Clasification","Type","Address","Zip Code" ;
FIELDSIZES 80,80,45,140,120 ;
OF oRanges COLOR RGB(0,0,0),RGB(252,214,251) SIZE 230,120 UPDATE

oBrw[1]:nMarqueeStyle:= MARQSTYLE_HIGHLCELL
oBrw[1]:bChange := { || browse2(which,oRangss,oBrw) }
oBrw[2]:nClrText = { || IIF(client->rent_sale,CLR_HBLUE,CLR_BLACK) }
oBrw[2]:nClrForeFocus= { || IIF(client->rent_sale,CLR_HGREEN,CLR_WHITE) }

oBrw[2]:bLDblClick := {|| sales1(which,oRangos,oBrw,aVar) }

oBrw[1]:CreateFromCode()
oBrw[2]:CreateFromCode()

ACTIVATE DIALOG oRanges CENTERED ON INIT (bar_v(oRanges),browse2(which,oRanges,oBrw))
RELEASE FONT oTipograf
clean_areas()
RETURN

//----------------------------------------------------------------------------//
STATIC FUNCTION browse2(which,oRanges,oBrw)
clean_areas()
SELECT Sales
SET ORDER TO TAG "price"
DBSETFILTER( &( "{|| sales->tip_ofr="+which+" .AND. sales->price_range="+STR(oBrw[1]:nRowSel-1,1,0)+"}"))
DBGOTOP()
oBrw[2]:REFRESH(.t.)
* oBrw[1]:REFRESH(.t.) //do nor refresh the first browse or it will NOT respond to the keyboard and WILL LOOSE the position when doble clicking the second one and returning from another browse
oRanges:REFRESH()
oRanges:UPDATE()
Return (nil)

So the moral of all this entire story:

a) Do NOT worry about creating your "skip", "up", "down", "bottom", and "up" code; it is already created for you on the XBrowse code.
b) Only REFRESH the dependent xBrowse
c) Use the oBrw:nRowSel data to get the browse row pointer to work with.

Maybe FiveWin should do an entire working example to include on a future version. It will help hours of researching with a simple solution to a common problem: two dependent browse windows

Emiliano Llano
ellano
 
Posts: 107
Joined: Tue Sep 15, 2009 7:52 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 145 guests