Tcbrowse 2 colour one for each line
- Patrick Mast
- Posts: 244
- Joined: Sat Mar 03, 2007 8:42 pm
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
With WBrowse also the standard codeblock works
For non-indexed dbf, we can use recno() instead of OrdKeyNo().
Obviously for arrays it is even simpler.
Code: Select all
oBrw:nClrPane := {||iif( OrdKeyNo() % 2 == 0, nEvenColor, nOddColor }
Obviously for arrays it is even simpler.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
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
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
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
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 :
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 :
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.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.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
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
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
G. N. Rao.
Hyderabad, India
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Although James solution is nice I would much prefer the simpler code as in your previous example:nageswaragunupudi wrote:Mr James
Your solution is a lot more elegant and works well. I agree we can drop considering any other alternative approaches.
Code: Select all
oBrw:nClrPane := { |nRow| iif( nRow % 2 == 0, rgb(255,255,235), rgb(192,208,179)) }
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
You can replace it withJames Bott wrote:Code: Select all
nRecs/2 = int(nRecs/2)
Code: Select all
nRecs % 2 = 0
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
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
>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
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
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.
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
G. N. Rao.
Hyderabad, India