record locking on Tcursors attached to UIObjects 
Author Message
 record locking on Tcursors attached to UIObjects

This is a question regarding how locking works when attaching a Tcursor
to a UIObject.  I have a MRO, through which users modify data.  When the
data is modified, I want to automatically add some additional audit
information to the record (user name, timestamp etc.).  I have many
UIObjects that operate on many different tables that all contain the
same audit info.  So this seems like a good candidate for a library
routine.

Here is how I have implemented it:

In the action method of my UIObject I trap for the DataPostRecord and
DataUnlockRecord events where the 'touched' property is True.
The code looks like this:

  case (id = DataUnlockRecord or id = DataPostRecord):
         if self.touched and not self.inserting then
            doDefault
            libAudit.auditTrail()     ;add audit info to record
         endif

The auditTrail() library routine attaches a Tcursor to the calling
UIObject -  i.e. tc.attach(subject) -  and enters the user name etc. in
the TCursor.

This all works fine for DataUnlockRecord events but not for
DataPostRecord events.  When a data post record event happens, the audit
info does not get inserted and the routine does not fail.

I guessed that it may have something to do with the fact the record
remains locked after a post.  So, I added code in my library to check
this and unlock it (and then restore the lock when done).  Lo and behold
it worked!  This is the code:

   ;If the subject record is locked, the audit trail will not be able
   ;to fill in audit info.   Therefore, check and unlock it if
neccessary.
   ;Save lock status and restore it when done.
   recordLocked = False
   if subject.recordStatus("Locked") then
      recordLocked = True
      subject.action(DataUnlockRecord)
   endif

   tc.attach(subject)
    tc.user = userName
 ;other stuff removed for brevity
   tc.close()

   ;restore lock status
   if recordLocked then
      subject.action(DataLockRecord)
   endif

Thanks for reading this far,  here is the question:  My problem is that
it seems very odd (certainly non-intuitive) that a Tcursor attached to a
UIObject does not inherit the lock (i.e. I cannnot make changes through
it).  Is this the way Paradox is supposed to work? or am I doing
something wrong?  This seems like alot of hoops to jump through to do
something as simple as fill in some fields that are in the table, but
not part of the MRO.



Mon, 25 Jun 2001 03:00:00 GMT
 
 [ 2 post ] 

 Relevant Pages 

1. Beginner Paradox Question Re : TableFrames/UIObjects/TCursors

2. Help! TCursor and UIObject

3. Help! TCursor and UIObject

4. Sync TCursor to UIobject

5. TCursors and UIObjects

6. tCursor record locks

7. VB4-16 Attached Oracle Record Locking

8. How to attach a Form to a tcursor object (PX4.5)

9. Highlighting the Current Record in a Table UIObject

10. Record Locking - Is there a way to test to see if a record has been locked

11. TCursor.Locate() and TCursor.qLocate() both fail

12. tCursor locks using dmAttach


 
Powered by phpBB® Forum Software