Home page Home page Home page Home page
Pixel Header R1 C1 Pixel
Pixel Header R2 C1 Pixel
Pixel Header R3 C1 Pixel
By Sprezz | Wednesday, 14 December 2011 16:22 | 0 Comments
A recent Works forum posting posed the question "Is it possible to set the color for individual rows in a popup rather than odd/even row colors?". Received wisdom is that "you cannot change colors on specific rows using COLOR_BY_POS due to the modality of the popup". This set the folks in Sprezz Towers to thinking about how this could actually be accomplished. This blog posting reflects the fruits of the combined thoughts and efforts of both the UK and Philadelphia Sprezz offices.

Take as a simple example a gender popup :-

It might be nice to render this as follows :-

To achieve this we need to be familiar with

  • User Defined Properties
  • The TIMER event
  • The TIMER property
  • The HANDLE property
  • The COLOR_BY_POS send_Message message.
  • The Window structure of a popup

User Defined Properties
The developer can add additional properties to any control within an OI app simply by setting a property name prefixed with an @. So call set_Property(@Window, "@SPREZZ", "FIDDLESTICKS") would set the @SPREZZ property of the current window to the value "FIDDLESTICKS". Any other process could retrieve this property using get_Property.

The TIMER event
The TIMER event is fired by OpenInsight as specified by the TIMER property regardless of whether the current dialog/popup/whatever is currently modal.

The TIMER property
The TIMER property tells the system when it should fire the TIMER event and at what intervals.

The HANDLE property
The HANDLE property provides a convenient shortcut to establish whether or not a control exists. If it exists it will have a handle.

The COLOR_BY_POS message
The COLOR_BY_POS message allows individual rows, columns or cells of an edit table to be set to a specific colour.

The Window structure of a popup
At its simplest a popup consists of an edit table (where the results are shown) and buttons for selection or cancelling. The edit table is always called POPUP.ET_POPUP.

It might be easier before actually showing the mechanics of how to achieve the effect required, to describe in simple terms how it is achieved. The key is in the seemingly innocous comment above that  "The TIMER event is fired by OpenInsight as specified by the TIMER property regardless of whether the current dialog/popup/whatever is currently modal".

Within our program that calls the popup we are going to do the following :-

  • Within the OPTIONS event for the prompt set two user defined properties
    • One listing the rows to have their colour set
    • One listing the colours to set the rows to
  • Set a TIMER event for the Window BEFORE calling the popup
  • Call the popup
  • Within the TIMER event, grab the user defined properties, set the colours using COLOR_BY_POS and then disable the TIMER event.
Whilst this may seem like a hack it works remarkably well with simple popups. Complex popups may require more error trapping. 

The OPTIONS event would look like this :-


   objxArray = @Window
   propArray = "@ROWS"
   dataArray = 1 : @Fm : 2

   objxArray := @Rm : @Window
   propArray := @Rm : "@COLOURS"
   dataArray := @Rm : BLUE$ : @Fm : PINK$

   objxArray := @Rm : @Window
   propArray := @Rm : "TIMER"
   dataArray := @Rm : 50

   dataArray = set_Property( objxArray, propArray, dataArray )

   retVal = popup( @Window, "", "GENDER")

   objxArray = object
   propArray = "DEFPROP"
   dataArray = retval

   dataArray = set_Property( objxArray, propArray, dataArray )


So we firstly indicate that we would like to change the colours of rows 1 and 2 of the popup. We then explain that we'd like them set to blue and pink (using some previously declared EQUATES). We then tell the TIMER event to kick off 50 milliseconds later and then we call the popup. On a successful return from the popup we accept the value and put it into the control that has just triggered this OPTIONS event.

So the popup will display and within 50 milliseconds the TIMER event will kick in. This has the following code :-


     objxArray = @Window
     propArray = "@ROWS"

     objxArray := @Rm : @Window
     propArray := @Rm : "@COLOURS"

     objxArray := @Rm : "POPUP"
     propArray := @Rm : "HANDLE"

     dataArray = get_Property( objxArray, propArray)

     rows    = dataArray[ 1, @rm]
     colours = dataArray[ Col2() + 1, @Rm]
     handle  = dataArray[ Col2() + 1, @Rm]

     if Len( handle ) then
        ptr1 = 1
        ptr2 = 1
           nextRow = rows[ ptr1, @Fm ]
           ptr1 = col2() + 1
        while len( nextRow )
            nextColour = colours[ ptr2, @Fm ]
            ptr2 = col2() + 1
            call send_Message("POPUP.ET_POPUP", "COLOR_BY_POS", 1, nextRow, nextColour)

        objxArray = @Window
        propArray = "TIMER"
        dataArray = ""
        dataArray = set_Property( objxArray, propArray, dataArray )


In this code we retrieve the rows to colour and the colours to set them to. We also retrieve the HANDLE  of the popup to ensure that it has been created successfully. If it has we use send_Message to colour the individual rows of the popup before setting the TIMER property to null to prevent it from being called again. In theory we ought to be able to set the TIMER property to 0 but there seems to be a bug in the 9.2.1 implementation which ignores the zero and continues calling the TIMER event.

Thus we are able simply to modify the popup after it has been launched.

In the next article in this series we will show how to add a button to the popup to call a user defined routine to display additional information about the current row in the popup.

Labels: , , ,


Post a Comment

Subscribe to Post Comments [Atom]

<< Home

Pixel Footer R1 C1 Pixel