VDF-GUIdance logo

  Visual DataFlex Logo

Shared knowledge leads to accumulated knowledge

        Printer Friendly Page

Contribution Record ID passed is empty.
Examines the filelist to see if any of the files would cause an error or lock timeout. It does that by running through the filelist the same way a lock or reread command would do and examining all of the opened files for its alias_mode and file_mode.
Call the procedure when a lock-error situation is known. It could also be called in your own error-handler object when an error number 4106 "Lock time-out" is encountered. See the example below.

For example you could argument Procedure Request_Save on a view and instead of forwarding the message just send DoTrackLockError. This would bring up the current situation of what would cause a lock time-out if you had forwarded Request_Save.
The other procedure doReportLockingDataFilesInfo tells you what the current filemodes of the opened files are. This is also useful when you want to track down lock errors.


ReportLock.pkg ~ 5 kB

Example integration

This code could be pasted on top of your application before any files are opened. I have placed this in my GlobalAllEnt.pkg file. That is the default name for the file created when you create a global subclass layer.
It creates an error object and hooks it onto the chain of error objects. If an error with error number 4106 (the lock timeout error) it runs through the filelist and gives a report in the debug view. The report consists of files that are currently locking the application and what should be done about it. Further more it outlines all opened files and their current lock status.

It also set the timeout to ONE SECOND (if using naive dataflex database) if this application is running on a developer machine. A developer machine is determined by the code if there is a special value in the registry database for the hkey_current_user section. But you can change that location and value to whatever you want. This is just an example that that illustrates how you can manage to have a low timeout for your self, and the higher default value for the end user.

Use Reportlock.pkg

Object RepErrorObject is a cObject
    Property Boolean Error_processing_state public False
    Property Handle OldErrorObject

    Procedure Error_report Integer iErrNum Integer iErrLine String sErrText
        Integer hId 
        Boolean bProcess
        Get Error_processing_state to bProcess
        If bProcess Procedure_Return
        Set Error_processing_state to True
        If (iErrNum = 4106) begin
            Send DoTrackLockError
            Send DoReportLockingDataFilesInfo
        Get OldErrorObject to hId
        Send Error_report to hId iErrNum iErrLine sErrText

        Set Error_processing_state to False 

    // Add the objektet to the list of errorobjects.
    Procedure DoAddRepErrorObj
        Set OldErrorObject to Error_Object_id
        Move Self to Error_Object_id

    // Lock Timeout is set to one second if this application is a developer edition.
    Procedure DoLowerTimeout
        Handle hReg
        String sValue
        Boolean bOpened bFound
        Get Create U_cRegistry to hReg
        If (hReg <> 0) Begin
            Set phRootKey of hReg to HKEY_CURRENT_USER
            Get OpenKey of hReg "Software\Nordteam Gruppen Aps" to bOpened
            If bOpened Begin
                Get ValueExists of hReg "Developermachine" to bFound
                If (bFundet) Begin
                    Get ReadString of hReg "Developermachine" to sValue
                    If (sValue = "YES") Begin
                        Set_Transaction_Retry to 0
                        Set_Attribute DF_LOCK_DELAY to 0
                        Set_Attribute DF_LOCK_TIMEOUT to 999    
                Send CloseKey of hReg
            Send destroy of hReg

Send DoAddRepErrorObj of RepErrorObject
Send DoLowerTimeout of RepErrorObject