Home page Home page Home page Home page
Pixel
Pixel Header R1 C1 Pixel
Pixel Header R2 C1 Pixel
Pixel Header R3 C1 Pixel
Pixel
By Captain C | Thursday, 8 October 2009 14:00 | 0 Comments
A common requirement when dealing with EditTables is to prevent a user from deleting a row on a case by case basis at runtime. In many applications we've seen this implemented by trapping the standard DELETEROW event and then sending an INSERT message with the deleted row contents, but this looks messy and unprofessional because the data disappears and reappears again.

A better way to do this is to trap the low-level ETM_DELETEROW notification sent by the EditTable prior to the actual DELETEROW event occuring. However, this notification has to be handled in a synchronous fashion (via a WINMSG event), and we also have to tell OpenInsight to return a special value from its own low-level internal message handler so that the EditTable stops the deletion (This last requirement is why the event has to be handled synchronously, because we need to return a value at the point in time that the message is sent).

We do this in two stages: First we tell OpenInsight to trap the WINMSG event for the EditTable and listen specifically for the ETM_DELETEROW message. This is normally done in a form's CREATE event like so:

0001     $insert logical
0002     
0003     equ WM_USER$       to 1024
0004     equ ETM_INSERTROW$ to (WM_USER$ + 2004)
0005     equ ETM_DELETEROW$ to (WM_USER$ + 2005)
0006  
0007     eventOp    = TRUE$ ; * // Turn tracking on
0008     eventOp<4> = TRUE$ ; * // Track Synchronously
0009     
0010     call send_Message( @window : ".TABLE_1", |
0011                        "QUALIFY_EVENT",      |
0012                        ETM_DELETEROW$,       |
0013                        eventOp )


Next we have to add a WINMSG event handler to the EditTable to catch the ETM_DELETEROW message:

0001     $insert logical
0002     
0003     equ WM_USER$       to 1024
0004     equ ETM_INSERTROW$ to (WM_USER$ + 2004)
0005     equ ETM_DELETEROW$ to (WM_USER$ + 2005)
0006     
0007     begin case
0008        case ( message = ETM_DELETEROW$ )
0009           * // Stop the delete here...
0010           call set_WinMsgVal( TRUE$, 0 )  ; * // Force PS to return 0 
0011                                           ; * // to Windows
0012           
0013     end case


Set_WinMsgVal

Notice the use of the Set_WinMsgVal function. This function only works from within a synchronous WINMSG event and it allows us to set the actual low-level value that OpenInsight returns internally from handling the ETM_DELETEROW message. Returning 0 here tells the EditTable not to allow the row deletion.

Preventing Row Insertion

We can also prevent users from inserting rows in a similar fashion, by trapping the ETM_INSERTROW message instead (which we've defined in the examples above). However, implementing this is an exercise left for the reader.

Labels: , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home

Previous Posts
Archives
BlogRoll

Powered by Blogger

Subscribe to
Posts [Atom]

 

 

Pixel
Pixel Footer R1 C1 Pixel
Pixel
Pixel
Pixel