Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL Server
Expertise: Beginner
Feb 27, 1997

Duplicate Win 95 Sorting

Question:
In Windows 95, all data represented in a tabular or table format can be sorted by clicking on the column heading. If you click once, it is in ascending order and if you click the same column again, it sorts in descending order.

Can this look and behavior be duplicated in Centura?

Answer:
First, I presume you know how to create a table window and how to populate it. If not, I would recommend you contact Centura Software Corporation and plan to attend one of its training courses. These courses are cost effective because you will learn in a week what would take you probably six months to learn on your own.

Second, the table window must be set up to capture for a click on a column header (gray area at top of each column). This is accomplished by setting a table flag on (TRUE); usually this is done at the time the child table window is created, but it could be done at any time you specify.

At the Message Action section of the table window:

On SAM_CreateComplete
  Call SalTblSetTableFlags(hWndForm, TBL_Flag_SelectableCols, TRUE)
     
Third, now that the table is able to capture for a click on a column header, you may use another message at the table window's Message Action section. When the customer clicks on a column header, it will be directed to this block of code and we will call a function we have created named ColumnSort. This function is expecting a number as a parameter, and conveniently enough, wParam in this case contains the column's window handle in the form of a number. (Window Handle is a unique address given to each window object such as a push button, data field, column and so on when they are created—Windows takes care of assigning this for you):
On SAM_ColumnSelectClick
  Call ColumnSort(wParam)
Now we will turn our attention to creating the function. This should be defined as a local function within the table window:
     01 Function: ColumnSort
     02   Description: Sample solution to question for inquiry.com
     03   Returns
     04   Parameters
     05           Number: nColHandle
     06   Static Variables
     07           Boolean: bSortOrder
     08           Number: nPreviousColumn
     09   Local variables
     10           Window Handle: hWndClickedCol
     11           Number: nIdClickedCol
     12   Actions
     13           Set hWndClickedCol  = SalNumberToWindowHandle( nColHandle
     14  )
     15           Set nIdClickedCol = SalTblQueryColumnID( hWndClickedCol )
     16           ! the sort order is a numeric value of either 0 or 1.  The
     17             constants are
     18           ! TBL_SortIncreasing (1) and TBL_SortDecreasing (0).
     19           If nIdClickedCol = nPreviousColumn
     20                   Set bSortOrder = NOT bSortOrder
     21                   ! Don't use FALSE - the code would not toggle
     22  between Ascending and Descending.
     23           Else
     24                   Set bSortOrder = TRUE
     25           Call SalTblSortRows( hWndForm, nIdClickedCol, bSortOrder )
     26           Set nPreviousColumn = nIdClickedCol

Code review:

     Line  Explanation
     05 - defines our parameter which is passed as wParam.
     07 - defines a static Boolean that will toggle the sort sequence
          between Ascending and Descending
     08 - defines a static numeric variable which will keep track of the
          previously used column id.
     10 - defines a local window handle, used for conversion.
     11 - defines a local number which will contain the column id.
     13 - Take the number passed to the function and convert it to a window
          handle.
     15 - take the window handle and find the column ID
     19 - compare the column id clicked with the previous column id
     20 - if they are the same - toggle the Boolean bSortOrder
     24 - if they are NOT the same, set bSortOrder = TRUE
     25 - Sort the column in Ascending order
     26 - Move the value of the current column to the variable
          nPreviousColumn
 
This code is well suited to migration into a class library. This will allow all your table windows to have this type of functionality and you don't ever have to think about this code again.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date