Tcbrowse 2 colour one for each line

User avatar
Patrick Mast
Posts: 244
Joined: Sat Mar 03, 2007 8:42 pm

Post by Patrick Mast »

Hey Guys,

Any idea how to do it with TWBrowse?
Tx

Patrick
AHF
Posts: 837
Joined: Fri Feb 10, 2006 12:14 pm

Post by AHF »

NageswaraRao,

Great job!

Thanks it works fine.

Antonio
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post by nageswaragunupudi »

With WBrowse also the standard codeblock works

Code: Select all

oBrw:nClrPane := {||iif( OrdKeyNo() % 2 == 0, nEvenColor, nOddColor }
For non-indexed dbf, we can use recno() instead of OrdKeyNo().
Obviously for arrays it is even simpler.
Regards

G. N. Rao.
Hyderabad, India
AHF
Posts: 837
Joined: Fri Feb 10, 2006 12:14 pm

Post by AHF »

Look out with OrdKeyNo.

I had to change it because in network enviroment the application speed its a big problem. See my previous messages.

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

Post by James Bott »

AHF,

I have modified my previous code sample to work without a database object. I works fine for me. If you will post your code perhaps I can tell why it wasn't working for you.

No changes to TCBrowse required.

Patrick, the portion of code for the setting the skipblock and colors will also work with TWBrowse.

Use the test code with FWH\samples\customer.dbf.

Regards,
James

Code: Select all

// Purpose : Sample TCBrowse with alternating color rows without a database object
// Author  : James Bott
// Date    : 1/9/2008

#include "fivewin.ch"
#include "TCBrowse.ch"    // <-- Important

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

   use customer
   cAlias := alias()

   define window oWnd title "TCBrowse Test"

   @ 0,0 browse oBrw of oWnd update

   oBrw:cAlias := cAlias

   add column to browse oBrw data (cAlias)->first

   add column to browse oBrw data (cAlias)->last

   lClrFlag:=.f.

   oBrw:bSkip:={| nRecs | (nRecs:= (cAlias)->(dbskipper( nRecs )), lClrFlag:=if(nRecs/2 = int(nRecs/2), lClrFlag,!lClrFlag), nRecs) }

   oBrw:nClrPane := { || if(lClrFlag, rgb(255,255,235), rgb(192,208,179)) }
   oBrw:nLineStyle:=0

   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 »

I totally agree with you. I never use them for these purposes.

In network environments never use ordkeyno or adskeyno for cosmetic jobs. Even otherwise limit use of the functions to absolute necessity.

But for browses of small tables and for local tables it is okay.

Adskeyno is even slower than ordkeyno. Also it involves round trips to the server and it is not good programming practice to increase network traffic for just cosmetic purposes or to place undue burden on the server. The difference is more pronounced when we deal with huge tables and hundreds of simultaneous users. Testing with smaller tables with a very few users will not give much problem though.

Relevant portions of ADS documentation of AdsGetKeyNum :
If the index is large, this function could take some time to complete because index keys are literally counted until the current key is reached.
If usFilterOption contains ADS_RESPECTFILTERS, the Advantage Client Engine must skip through all records referenced by keys in the index that pass the filter and/or scope and count them until the current key is reached. Thus, with large indexes where many records pass the filter and/or keys pass the scope, this function can be very slow.
That is the reason i prefer a solution from the browse class itself. Merit of this approach is that same code works without regard to the rdd or the datasource. I am trying to make similar modifications to txbrowse class.
Regards

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

Post by nageswaragunupudi »

Mr James

Your solution is a lot more elegant and works well. I agree we can drop considering any other alternative approaches.

I should have tested your approach first. Why did Mr AHF report this approach was not working for him? Working fine for me.

Thank you Mr James
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,

Thanks for confirming that it does work. I don't know why AHF has been unable to get it working. Hopefully he will run the test code and report back.

James
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post by nageswaragunupudi »

Mr James

Your code works well with tcbrowse and twbrowse.
I am having some issues with txbrowse. :cry:
Regards

G. N. Rao.
Hyderabad, India
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

nageswaragunupudi wrote:Mr James

Your solution is a lot more elegant and works well. I agree we can drop considering any other alternative approaches.
Although James solution is nice I would much prefer the simpler code as in your previous example:

Code: Select all

oBrw:nClrPane := { |nRow| iif( nRow % 2 == 0, rgb(255,255,235), rgb(192,208,179)) }
EMG
AHF
Posts: 837
Joined: Fri Feb 10, 2006 12:14 pm

Post by AHF »

James,

Sorry to miss lead you.

Your code works well, however I have several bskip s and it's much easy to alter my own inherited TcBrowse class instead of chekcing out all bskip s.

Once more thanks to all for your help.

Antonio
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

James Bott wrote:

Code: Select all

nRecs/2 = int(nRecs/2)
You can replace it with

Code: Select all

nRecs % 2 = 0
EMG
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

AGF,

>Your code works well, however I have several bskip s and it's much easy to alter my own inherited TcBrowse class instead of chekcing out all bskip s.

OK, glad to hear it worked for you. Granted it will be easier right now to use the modified TCBrowse, but then you will have to modify each new version of FWH. If you getting monthly updates of FWH, then that will be more work.

It would be better to create a subclass of TCBrowse. Then you don't need to modify the original TCBrowse source for each new version of FWH.

Modifying the bSkips also would prevent you from having to make any changes with new versions of FWH.

Regards,
James
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post by nageswaragunupudi »

Personally I prefer solutions without having to change FWH source code. ( Not that I never do it, but it is really a tedious work to keep making changes with every FWH upgrade ), unless Mr. Antonio likes to make a solution part of next release.

There is one issue to rely on bSkip block. It depends on the way the browse object uses the bSkip block. TWbrowse and TCBrowse behave similarly. TXBrowse behaves a bit differently.

We prefer a way which works for all browses and also does not rely on the data source.

I still feel it is better if the browse objects provide evaluation of the bClrPane block or bClrStd block with the visual row number ( or lEvenRow) as parameter. In fact that seemed to be the original intention of the author(s) of TCBrowse.
Regards

G. N. Rao.
Hyderabad, India
AHF
Posts: 837
Joined: Fri Feb 10, 2006 12:14 pm

Post by AHF »

I agree.
I use already a Tcbrowse subclass.

Antonio
Post Reply