TechTricks
Technical answers from the trenches 
 
 
 
 

     
   
Highlighting Records in Table Frames
 
   
 Posted: 7 January 2001
 
   
 
 Applies to: Paradox 5.0 and later
 
   
 
Audience: Intermediate
 
       
   

Question: How do I highlight the active record in a table frame?

Answer: There are many things that Paradox makes easy; sadly, this isn't one of them. Fortunately, you can do this by adding code to five places on the table frame:

Step 1: In the Constant window, declare a constant for the color you want to use for the highlight. For example:

Const
   HL_COLOR = Yellow   ; Highlight Color
endConst

Step 2: In the Var window, declare three variables:

Var
   uiFld,               ; Pointer to first field in the frame.
   uiRec      UIObject  ; UI Objects to highlight
   loHilite   Logical   ; Highlight Record enabled?
endVar

Step 3: Next, add the following code to the table frame's action() event:

method action(var eventInfo ActionEvent)

; Now, highlight the selected record, if necessary

   if eventInfo.actionClass() = DataAction then

      If not loHilite.isAssigned() then
         return
      endIf

      ; See if the record should be highlighted.

      if loHilite = TRUE then

         delayScreenUpdates( TRUE )    ; Make sure repaints happen at once
         uiRec.Color = container.color ; Reset the record’s color
         loHilite = FALSE

         doDefault                     ; Let the action take place

         loHilite = TRUE
         uiRec.attach( uiFld.containerName )
         uiRec.color = HL_COLOR        ; Highlight the current record
         uiRec.Translucent = TRUE
         delayScreenUpdates( False )   ; Allow repaints to happen now

      endif
   endif
endMethod

Step 4: To make sure that the form initializes properly, add this to the table frame's open() event:

method open(var eventInfo Event)

   loHilite = FALSE
   doDefault

   ;// Get first UI Field in tableframe and attach to it.

   uiFld.attach( self.firstRow )
   uiFld.attach( uiFld.first )
   uiFld.attach( self.fullname + "." + uiFld.name )

   ;// Get UI Record in tableframe and attach to it.

   uiRec.attach( uiFld.containerName )
   loHilite = TRUE

endMethod

Step 5: Finally, it's a good idea to make certain the highlight is removed when the table frame closes. To do so, add the following to its close() event:

method close(var eventInfo Event)

   uiRec.Color = Self.Color

endMethod

Remember: All code goes into the TableFrame object, not the record object.

While this looks like a lot of work, it goes quickly, especially if you use the sample provided in our Download area. Copy the table frame to the Clipboard and then paste it into your form.

How it works

If you dig into the code, you'll find it's based on a rather neat solution based on the way Paradox resolves incomplete object references. Specifically, note the value assigned to the uiFld object during the open() event:

uiFld.attach( self.fullname + "." + uiFld.name )

Because this is an incomplete object name, Paradox is forced to determine your intent from the available objects, e.g. the ones with names starting with the full name of the table frame and ending with the field object in question. Since this happens to be all rows visible in the table frame, Paradox chooses the active one, e.g. the one with focus.

Normally, it's best to be specific with Paradox, that is, you often need to tell it the precise object you're trying to affect. In this case, however, the general reference gives us the behavior we need without knowing the full name of the object in question. (Don't worry if you find this explanation a bit confusing; it threw us for a loop when we first ran into it. It'll become clearer as you become more familiar with Paradox's behavioral idiosyncrasies.)

Note: This implementation is based on one originally documented by Mark Pauker in the September 1994 issue of The Paradox Informant, a title that is (sadly) no longer published. Our implementation has been refined over the years, but the basic technique is based on Mr. Pauker's work.

Caution: Try to avoid adding additional code to the table frame's action() event. If you need business rules or other forms of processing (such as custom lookups, confirming deleted records, and so on, it's best to implement those on the record object, not the table frame.

A future article will discuss ways of consolidating this into a more general solution that is easier to share between forms.

 

       

Top

Feedback About Paradox Delphi Assorted Web Stuff
 
 
Copyright © 2000-2004, techtricks.com; All Rights Reserved.
Acknowledgements, Disclaimers, Terms and Conditions.
Article last updated on 31 May 2003

 

Other Sites: Paradox, Delphi, Perl, Web Stuff, and More


 

[- End -]