How to determine if exclusive open will succeed in foxpro?
-
09-09-2019 - |
Question
If I attempt to gain an exclusive table open in FoxPro, it generates a dialog box if access is denied. Since I'm targeting an non-interactive application, is there a way to detect whether the operation will succeed, or at least have it fail silently?
Solution
If you have VFP 8 or greater:
TRY USE MyTable IN 0 EXCLUSIVE ENDTRY ... IF USED ("MyTable") *-- Use the table here ENDIF
OTHER TIPS
For older versions:
cOldError = ON("ERROR")
ON ERROR *
USE MyTable IN 0 EXCLUSIVE
lSuccess = used("MyTable")
ON ERROR &cOldError
if lSuccess ...
I've had success using FOPEN...
nFHdl = FOPEN("myfile.dbf", 1) && 1 tries to open the file for writing
IF nFHdl > 0 THEN
FCLOSE(nFHdl)
USE myfile.dbf exclusive
ELSE
= messagebox("Can't open Exclusive")
ENDIF
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow