Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MoveFolders problem
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00446793
Message ID:
00447480
Views:
8
>>Nadya:
>>
>>>
>>Suppose, I have a table open shared. I want to open it shared at another user station. How can I check, what this table is not opened exclusively already? Fopen() always returns -1 regardless of the second parameter. Do I really need to use Error Handler here or there is another way?
>>>
>>
>>Why not write a custom class wrapper for the use command and trap the error there? For example, the class could have an Exclusive property and a Use method. If Use raises an error code 3 when Exclusive is False, you then know the file is used exclusively by another user.
>>
>>Daniel
>
>I just did. See, if you find problems in this code:
>
>     =messagebox(tcTable +' is opened exclusively by another user. Can not proceed...',48)
>               return .f. && Table could not be opened (already used exclusively)
Unpost!!!!!!

This is the program (above code should not contain problems other than words misuse :))
********************************************************************
*  Description.......: OpenTable
*  Calling Samples...: OpenTable('TranMstr','WorkFile')
*  Parameter List....: tcTable, tcAlias, tcMode
*  Created by........:
********************************************************************
function opentable
lparameters tcTable, tcAlias, tcMode
* tcTable - should be name of table to open (with or without full path)
*             database  name should not be included with !, use gettable instead
* tcAlias - optional alias name, if different from pcTable
* tcMode - optional mode in which table should be opened, like Shared noupdate

* Check parameters first
if empty(tcTable) or vartype(tcTable)<>'C'
     return .f.
endif
if empty(tcMode) or vartype(tcMode)<>'C'
     tcMode='shared'
else
     tcMode=lower(tcMode)
endif
tcAlias=iif(empty(tcAlias),juststem(tcTable),tcAlias)
if !used(tcAlias)
     local fh
     if 'excl' $ tcMode && Esclusive mode was specified
          fh=fopen(forceext(tcTable,'dbf'),12) && Check, if table could be open exclusively
          if fh>0 and fclose(fh) && File could be opened exclusively
               use (tcTable) again &tcMode in 0 alias (tcAlias)
          else
               =messagebox(tcTable +' is opened exclusively by another user. Can not proceed...',48)
               return .f. && Table could not be opened (already used exclusively)
          endif
     else
          local lcOldError, lnVar
          lnVar=0
          lcOldError=on('error')
          on error lnVar=error()
          use (tcTable) again &tcMode in 0 alias (tcAlias)
          on error &lcOldError
          if lnVar<>0 && Error occurs
               if lnVar=1705 && File Access is denied
                    =messagebox(tcTable +' is opened exclusively by another user. Can not proceed...',48,'Error')
                    return .f. && Table could not be opened (already used exclusively)
               else && Another error
                    =messagebox(tcTable+' could not be opened!',48,'Error')
               endif
          endif
     endif
else
     select (tcAlias)
endif
return .t.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform