Ask Dr. De Phobia - Questions and Answers about Clarion

by Jim DeFabia

Published 1998-07-01    Printer-friendly version

NOTE: Clarion Magazine was not able to obtain an archive of the original source code for this article. If you have the source, we'd very much appreciate it if you would email it to us so we can post it for other readers.

Q: 

I want to display rows in a listbox in alternating colors or "greenbar paper" style. In other words, I want every other row to have a grey background. I thought I could use the BrowseBox control template's conditional colorization and modulus division, but due to the BrowseBox page-loading this does not work. Do you have any suggestions?

A: 

Yes, I have two suggestions--one is bad; the other good. First the bad suggestion: You could get a piece of transparent film with stripes on it and tape it to your monitor. But, that would require installation by all your users and you would have to ship tape with all your installation disks, so let's take another approach.

You are correct in your assessment that the BrowseBox's page-loading scheme must be handled for this to work properly. . You gain many benefits from page-loading, but with these benefits comes some responsibilities when coding.

Color attributes are stored in the QUEUE used as the FROM attribute of the LIST. Using the built-in Conditional Colorization works whenever a complete "page" of records replaces the current values stored in the QUEUE, but scrolling one-by-one will cause it to fail. What you need to do is loop through the QUEUE every time a NewSelection event occurs (every time the user manipulates the list control). This adds very little overhead because the queue is in memory and never contains more than a page of records (in most cases twenty or so)

This is a good example of a time when deriving a method in the ABC classes is the best approach. Clarion 4 and the ABC templates allow you to do this easily.

From the Window Formatter:

  1. Right-click on the BrowseBox control, then select Actions.
  2. Use the tab's scroll button to select the Classes tab.
  3. Check the Derive box.
  4. Press the New Class Methods button.
  • We will add a new method to the browse object. Since you refered to the alternating colors as Greenbar paper, we'll call this new method Greenbar.
  1. Press the Insert button.
  2. Specify Greenbar as the New Method Name.
  3. Specify ( ) as the New Method Prototype, then press tab.

This enables the Data Embed and Code Embed buttons.

NCM.gif

  1. Press the Code Embed button and insert the following Source Code:
LOOP I# = 1 to RECORDS(SELF.Q)
  GET(SELF.Q, I#)
  ASSERT(NOT ERRORCODE())
  EXECUTE (I# % 2) +1
    BEGIN
      ! Apply Normal background color to every field
      ! displayed in LIST on alternating rows
      SELF.Q.MEM:MemberNumber_NormalBG = COLOR:Silver
      SELF.Q.MEM:LastName_NormalBG = COLOR:Silver
      SELF.Q.MEM:FirstName_NormalBG = COLOR:Silver
    END
    BEGIN
      ! Reset Normal background color to every field
        displayed in LIST on alternating rows
      SELF.Q.MEM:MemberNumber_NormalBG = -1
      SELF.Q.MEM:LastName_NormalBG = -1
      SELF.Q.MEM:FirstName_NormalBG = -1
    END
  END
  PUT(SELF.Q)
  ASSERT(NOT ERRORCODE())
END
  1. Save and Exit Back to the Window Formatter.
  2. double-Click on the BrowseBox control to call the Embedded Source Dialog.
  3. In the Control Event Handling, NewSelection embed point, add the following code:
BRW1.Greenbar !Call Method to apply alternating colors

BRW1 is the name of the BrowseBox object. We call it explicitly (instead of using the SELF.method convention because we are calling it from outside the object).

  1. Save and exit back to the Embedded Source Dialog.
  2. In the Control Event Handling, ScrollDrag embed point, add the following code:
POST(EVENT:NewSelection,?Browse:1)

This ensures the colorization occurs when the user drags the thumb up or down. ScrollDrag does not automatically produce a NewSelection Event.

Image24.gif

  1. Save and exit back to the Application Tree.
  2. Press the Make and Run button.

Your alternating colors should appear as you want. So throw away your transparencies and highlighter pens!

runapp.gif

Submit your questions to DrD@clariononline.com.

Printer-friendly version

Reader Comments

To add a comment to this article you must log in.

 
 

Search

 

Advanced Search
Topical Index

Related Articles

Subscribe to
ClarionMag

One year: $189

(includes all back issues since '99)

Renewals from $139

Two years: $289

Renewals from $239

More Info

Subscribe Now!

ClarionMag Blog

RSS Feeds

Updates via Email

Enter your Email


Powered by FeedBlitz

Quick Links