XBrowse alternating row colors

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

XBrowse alternating row colors

Post 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
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post by nageswaragunupudi »

Mr James

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

G. N. Rao.
Hyderabad, India
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
George
Posts: 710
Joined: Tue Oct 18, 2005 6:49 pm

Post by George »

James,
Can TDATA work with ADS database, ADT extension?

Regards,

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

Post 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
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post 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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
User avatar
TimStone
Posts: 2536
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA
Contact:

ADS / ADT

Post 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.
Tim Stone
http://www.MasterLinkSoftware.com
timstone@masterlinksoftware.com
Using: FWH 19.06 with Harbour 3.2.0 / Microsoft Visual Studio Community 2019
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post by nageswaragunupudi »

Here is a sceen shot
Image

It is breaking sometimes like this
Regards

G. N. Rao.
Hyderabad, India
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
User avatar
richard-service
Posts: 583
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan
Contact:

Post 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
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post by nageswaragunupudi »

Exactly the same code and same dbf. Copied and Pasted. I am workin with 8.01
Regards

G. N. Rao.
Hyderabad, India
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
Post Reply