A PowerBuilder Color Function


While I was working on my PowerBuilder Color Chart, I started thinking about how we use color values in PB datawindow expressions.

If you wanted to give every other row in a datawindow a gray background, you might put something like this in the detail band's background expression:
if (mod(getrow(), 2) = 0, 16777215, 8421504))
But you'd have to know that 16777215 represents white and 8421504 is the number for gray.

A lot of developers take the next step and use the RGB function:
if (mod(getrow(), 2) = 0, RGB(255, 255, 255), RGB(128, 128, 128))
Here you specify the Red, Green and Blue values for the color you want and the RGB function returns the proper number.

It's still not very easy to tell at a glance what the color is, but it's certainly easier than the first expression.

I wanted an easier way to specify a color. So I created a new function, f_color. You pass it one of the PowerBuilder color names and it will return the proper number. For example, our alternate row highlighting expression now becomes:
if (mod(getrow(), 2) = 0, f_color("White"), f_color("Gray"))
Plus, you can now do things like use Transparent and the Window colors:
if (mod(getrow(), 2) = 0, f_color("Transparent"), f_color("Button Face"))
I've made it available here. Just select File -> Download from the Google Docs page that appears.





Comments

Popular posts from this blog

Restoring Color Icons in Gimp 2.10

My Nullable DateTime Picker

PowerBuilder and SQL Server: Tips On Working Together