How to create TxBrowse in For...Next loop

How to create TxBrowse in For...Next loop

Postby bosibila » Tue Sep 02, 2008 10:10 pm

Hello,

I need some help for specific TXBrowse() example.
Is there way to create txbrowse for database from array (like old dbedit function)?

*----------------------------------------------------------------------------------
use customer
aHead:={}
aField:={}
aFormt:={}
aadd( aHead,"First" ); aadd( aHead,"Second"); aadd( aHead,"Amount" )
aadd( aField,"first" ); aadd( aField,"second"); aadd( aField,"amo" )
aadd( aFormt,"@!" ); aadd( aFormt,"@!"); aadd( aFormt,"@999,999.99" )

My idea is to create txbrowse in For...Next loop using down shown example. Is it possible?

For nFor=1 to 3
oCol:= oBrw:AddCol()
oCol:bStrData := { || customer->first } //??
oCol:bEditvalue := { || customer->first } //??
oCol:cEditPicture := aFormt[nFor]
oCol:cHeader := aHead[nFor]
oCol:nEditType := 1
next

Best regards,
Boris (FWH 20.07, xHarbour 1.2.3, Harbour 3.2.0, BCC74, MySql 5.7)
User avatar
bosibila
 
Posts: 53
Joined: Wed Aug 06, 2008 5:27 pm
Location: Osijek, Croatia

Postby nageswaragunupudi » Tue Sep 02, 2008 10:27 pm

Very very easy.

Assume we have these arrays:

aCols // array of field names
aPics // array of picture formats
aHeaders // array of headers

@ 0,0 XBROWSE oBrw ;
COLUMNS aCols ;
PICTURES aPics ;
HEADERS aHeaders ;
OF oWnd ;
ALIAS "aliasname"

My personal advice. Avoid using old way of creating coluimns and assigning codeblocks. This requires good understanding how the xbrowse works. Command syntax is very powerful and flexible and lets us produce "bug-free" code in "few lines", in seconds rather than in minutes, easily readable and easily matintainable

By the way, only XBrowse command allows us to give the lists either as inline lists or as arrays
Last edited by nageswaragunupudi on Tue Sep 02, 2008 10:41 pm, edited 1 time in total.
Regards

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

Postby nageswaragunupudi » Tue Sep 02, 2008 10:37 pm

Still if you want to stick to the old style of programming, here is the way


USE CUSTOMER

oBrw := TXBrows():New( oWnd ) // recommended TXBrows() not TXBrowse()
oBrw:cAlias := 'CUSTOMER' // please never never ommit this

for n := 1 to 3
CreateCol( oBrw, n, aData, aPics, aHeader )
next n

oBrw:CreateFromCode()
... etc ..

static func CreateCol( oBrw, n, aData, aPics, aHeader )

WITH OBJECT oBrw:AddCol()
:bEditValue := aData[ n ] / /aData is array of codeblocks
:cEditPicture := aPics[ n ]
:cHeader := aHeader[ n ]
END

return oCol

Note: Never create codeblocks in a loop using loop index. This is the thumb rule not only for xbrowse, but for any purpose. Use a function instead.
Regards

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

Postby bosibila » Tue Sep 02, 2008 10:47 pm

Thanks, you give me great help.
Boris (FWH 20.07, xHarbour 1.2.3, Harbour 3.2.0, BCC74, MySql 5.7)
User avatar
bosibila
 
Posts: 53
Joined: Wed Aug 06, 2008 5:27 pm
Location: Osijek, Croatia

Postby nageswaragunupudi » Tue Sep 02, 2008 10:59 pm

By the way, we need Version 8.08 for the above command syntax to work with arrays.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10653
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 32 guests

cron