FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to create TxBrowse in For...Next loop
Posts: 53
Joined: Wed Aug 06, 2008 05:27 PM
How to create TxBrowse in For...Next loop
Posted: 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)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
How to create TxBrowse in For...Next loop
Posted: 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

Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
How to create TxBrowse in For...Next loop
Posted: 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
Posts: 53
Joined: Wed Aug 06, 2008 05:27 PM
How to create TxBrowse in For...Next loop
Posted: 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)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
How to create TxBrowse in For...Next loop
Posted: 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

Continue the discussion