Page 1 of 3

XBrowse alternating row colors

Posted: Mon Jan 21, 2008 7:03 pm
by James Bott
There was a recent discussion of how to set alternating row colors in browses. I showed a way to do this for TWBrowse and TCBrowse. Here is an example for TXBrowse using the same technique.

James

Code: Select all

/*
Purpose : TXBrowse with alternating row colors
Author  : James Bott
Language: FWH
Date    : 1/20/2008
*/


#include "fivewin.ch"
#include "xbrowse.ch"

#define COLOR_LIGHT  rgb(255,255,235)
#define COLOR_DARK  rgb(192,208,179)

function main()
   local oWnd,oBrw,oCust,oCol,lClrFlag

   oCust:= TData():new(,"customer")
   oCust:use()

   define window oWnd

   oBrw := TXBrowse():New( oWnd )

   oCol := oBrw:AddCol()
   oCol:cHeader       := "First"
   oCol:bStrData      := { || oCust:first }

   oCol := oBrw:AddCol()
   oCol:cHeader       := "Last"
   oCol:bStrData      := { || oCust:last }

   // Setup alternating row flag
   lClrFlag:=.f.
   oBrw:bSkip:={| nRecs | (nRecs:= oCust:skipper( nRecs ), lClrFlag:= if( nRecs % 2 = 0, lClrFlag,!lClrFlag), nRecs) }


   // Define alternating row colors
   oBrw:bClrStd:= {|| if(lClrFlag,{ CLR_BLACK, COLOR_LIGHT },{ CLR_BLACK, COLOR_DARK }) }

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW

   oBrw:bBookMark := {| n | iif( n == nil,(oCust:RecNo()),(oCust:GoTo(n)) ) }  // Required!
   oBrw:cAlias := oCust:cAlias

   oBrw:lRecordSelector:=.f.

   // This must be at the end of browse code as it initializes the columns
   // E.G. Cols inherit row colors from the parent browse
   oBrw:CreateFromCode()

   oWnd:oClient:= oBrw

   activate window oWnd

return nil

Posted: Mon Jan 21, 2008 7:21 pm
by nageswaragunupudi
Mr James

I am interested in trying this out. But can you kindly give the code without using any data class please?

Posted: Mon Jan 21, 2008 9:52 pm
by James Bott
NageswaraRao,

Of course. I forget that lots of you are still not using database objects. I highly encourage you to use them as you will save hundreds, maybe thousands, of lines of code in your applications. With a database object you don't have to use any scatter/gather functions and there is no dealing with aliases. There are lots of other good reasons to use objects too.

Below is the code without a database object. Test it with \samples\customer.dbf.

James

Code: Select all

/*
Purpose : TXBrowse with alternating row colors
Author  : James Bott
Language: FWH
Date    : 1/20/2008
Notes   : Without using a database object
*/


#include "fivewin.ch"
#include "xbrowse.ch"

#define COLOR_LIGHT  rgb(255,255,235)
#define COLOR_DARK  rgb(192,208,179)

function main()
   local oWnd,oBrw,oCust,oCol,lClrFlag, cAlias

   use "customer" shared alias "cust"
   cAlias := alias()

   define window oWnd title "XBrowse Row Color Test"

   oBrw := TXBrowse():New( oWnd )

   oCol := oBrw:AddCol()
   oCol:cHeader       := "First"
   oCol:bStrData      := { || (cAlias)->first }

   oCol := oBrw:AddCol()
   oCol:cHeader       := "Last"
   oCol:bStrData      := { || (cAlias)->last }

   // Setup alternating row flag
   lClrFlag:=.f.
   oBrw:bSkip:={| nRecs | ( if(nRecs == nil, nRecs := 1,),nRecs:= (cAlias)->(dbskipper( nRecs )), lClrFlag:= if( nRecs % 2 = 0, lClrFlag,!lClrFlag), nRecs) }

   // Define alternating row colors
   oBrw:bClrStd:= {|| if(lClrFlag,{ CLR_BLACK, COLOR_LIGHT },{ CLR_BLACK, COLOR_DARK }) }

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW

   oBrw:bBookMark := {| n | iif( n == nil,(cAlias)->(RecNo()), (cAlias)->(dbgoto(n)) ) }  // Required!
   oBrw:cAlias := cAlias

   oBrw:lRecordSelector:=.f.

   // This must be at the end of browse code as it initializes the columns
   // E.G. Cols inherit row colors from the parent browse
   oBrw:CreateFromCode()

   oWnd:oClient:= oBrw

   activate window oWnd

return nil

Posted: Mon Jan 21, 2008 11:08 pm
by George
James,
Can TDATA work with ADS database, ADT extension?

Regards,

George

Posted: Mon Jan 21, 2008 11:12 pm
by James Bott
George,

>Can TDATA work with ADS database, ADT extension?

I believe so. Tim Stone is using it with ADS, but I'm not sure about the ADT extension. What is that? I have not used ADS.

Perhaps Tim can answer that.

If there are some special requirements, I'm sure you could subclass TData.

Regards,
James

Posted: Mon Jan 21, 2008 11:32 pm
by Otto
Hello James,
About to start using TData I read:
TData always opens a file in a new workarea with a unique alias.

Is there no limit of currently opened files (256) anymore ?
Regards,
Otto

Posted: Mon Jan 21, 2008 11:53 pm
by James Bott
Otto,

>Is there no limit of currently opened files (256) anymore ?

I don't know the limit but I have never reached it. I just did a test and opened 999 copies of the same file without a problem. I have never had a TData user report a problem either.

With objects you really need this capability. This makes coding so much easier.

James

ADS / ADT

Posted: Tue Jan 22, 2008 12:21 am
by TimStone
I've never tried it with the ADT extensions. tData is a valuable extension to the FWH tDatabase class ... so if that works, I would expect tData would handle them fine.

I use data objects exclusively. It makes my coding life a whole lot simpler, and the work with everything.

Posted: Tue Jan 22, 2008 12:47 am
by James Bott
Here is another important point about database objects. It is not an all or nothing situation. You can use database objects in the same program that you use regular databases. This way you can convert an existing application a little at a time, or you can just use objects when you add to an existing application.

James

Posted: Tue Jan 22, 2008 7:58 am
by nageswaragunupudi
Here is a sceen shot
Image

It is breaking sometimes like this

Posted: Tue Jan 22, 2008 8:23 am
by James Bott
NageswaraRao,

>It is breaking sometimes like this

It works fine for me.

Your sreenshot leads me to believe you are not using exactly the same code I posted. Can I see your code? Are you using filters or indexes?

James

Posted: Tue Jan 22, 2008 8:34 am
by James Bott
NageswaraRao,

I have just tested it with an index and a filter and it is still working fine for me.

I am using FWH 8.01. What version are you using?

James

Posted: Tue Jan 22, 2008 1:12 pm
by richard-service
James Bott wrote:NageswaraRao,

I have just tested it with an index and a filter and it is still working fine for me.

I am using FWH 8.01. What version are you using?

James
Hi James,

I test your code same as nageswaragunupudi problem.
I use FWH0712

Regards,

Richard

Posted: Tue Jan 22, 2008 2:33 pm
by nageswaragunupudi
Exactly the same code and same dbf. Copied and Pasted. I am workin with 8.01

Posted: Tue Jan 22, 2008 9:18 pm
by James Bott
Richard and NageswaraRao,

I am at a loss as to why it isn't working for you. I'm thinking it must be differences in TXBrowse. NageswaraRao, didn't you say in another message thread that you are using a modified TXBrowse? Could you be linking in this instead of the standard FWH version?

I am using xHarbour, are you?

James