FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Tcbrowse 2 colour one for each line
Posts: 246
Joined: Sat Mar 03, 2007 08:42 PM
Tcbrowse 2 colour one for each line
Posted: Thu Jan 10, 2008 03:08 PM

Hey Guys,

Any idea how to do it with TWBrowse?
Tx

Patrick

Posts: 838
Joined: Fri Feb 10, 2006 12:14 PM
Tcbrowse 2 colour one for each line
Posted: Thu Jan 10, 2008 03:33 PM

NageswaraRao,

Great job!

Thanks it works fine.

Antonio

Regards

Antonio H Ferreira
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Tcbrowse 2 colour one for each line
Posted: Thu Jan 10, 2008 04:10 PM
With WBrowse also the standard codeblock works
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
Posts: 838
Joined: Fri Feb 10, 2006 12:14 PM
Tcbrowse 2 colour one for each line
Posted: Thu Jan 10, 2008 04:29 PM

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

Regards

Antonio H Ferreira
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Tcbrowse 2 colour one for each line
Posted: Thu Jan 10, 2008 04:51 PM
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

// 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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Tcbrowse 2 colour one for each line
Posted: Thu Jan 10, 2008 04:52 PM
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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Tcbrowse 2 colour one for each line
Posted: Thu Jan 10, 2008 04:58 PM

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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Tcbrowse 2 colour one for each line
Posted: Thu Jan 10, 2008 05:08 PM

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Tcbrowse 2 colour one for each line
Posted: Thu Jan 10, 2008 05:35 PM

Mr James

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

Regards



G. N. Rao.

Hyderabad, India
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Tcbrowse 2 colour one for each line
Posted: Thu Jan 10, 2008 06:20 PM
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:

oBrw:nClrPane := { |nRow| iif( nRow % 2 == 0, rgb(255,255,235), rgb(192,208,179)) }


EMG
Posts: 838
Joined: Fri Feb 10, 2006 12:14 PM
Tcbrowse 2 colour one for each line
Posted: Thu Jan 10, 2008 06:52 PM

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

Regards

Antonio H Ferreira
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Tcbrowse 2 colour one for each line
Posted: Thu Jan 10, 2008 07:32 PM
James Bott wrote:
nRecs/2 = int(nRecs/2)


You can replace it with

nRecs % 2 = 0


EMG
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Tcbrowse 2 colour one for each line
Posted: Thu Jan 10, 2008 11:56 PM

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Tcbrowse 2 colour one for each line
Posted: Fri Jan 11, 2008 03:03 AM

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
Posts: 838
Joined: Fri Feb 10, 2006 12:14 PM
Tcbrowse 2 colour one for each line
Posted: Fri Jan 11, 2008 08:40 AM

I agree.
I use already a Tcbrowse subclass.

Antonio

Regards

Antonio H Ferreira