XBrowse alternating row colors

XBrowse alternating row colors

Postby James Bott » Mon Jan 21, 2008 7:03 pm

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  Expand view
/*
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
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby nageswaragunupudi » Mon Jan 21, 2008 7:21 pm

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
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby James Bott » Mon Jan 21, 2008 9:52 pm

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  Expand view
/*
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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby George » Mon Jan 21, 2008 11:08 pm

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

Regards,

George
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Postby James Bott » Mon Jan 21, 2008 11:12 pm

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

Postby Otto » Mon Jan 21, 2008 11:32 pm

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
Otto
 
Posts: 6314
Joined: Fri Oct 07, 2005 7:07 pm

Postby James Bott » Mon Jan 21, 2008 11:53 pm

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

ADS / ADT

Postby TimStone » Tue Jan 22, 2008 12:21 am

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
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2943
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Postby James Bott » Tue Jan 22, 2008 12:47 am

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

Postby nageswaragunupudi » Tue Jan 22, 2008 7:58 am

Here is a sceen shot
Image

It is breaking sometimes like this
Regards

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

Postby James Bott » Tue Jan 22, 2008 8:23 am

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: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby James Bott » Tue Jan 22, 2008 8:34 am

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

Postby richard-service » Tue Jan 22, 2008 1:12 pm

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

Postby nageswaragunupudi » Tue Jan 22, 2008 2:33 pm

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

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

Postby James Bott » Tue Jan 22, 2008 9:18 pm

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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Maurizio and 40 guests