Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checking for Locked Files
Message
From
28/06/1999 06:16:36
Paul Frost
Instem Computer Systems Ltd
Stone, United Kingdom
 
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
00233514
Message ID:
00234675
Views:
27
>>>there is the danger that another will grab the file in the small time window between the fclose & the use & there's no guarantee that the -1 return is due to the file already being open - it may not exist for example, but extra code code be put in to test these conditions if required.
>
>
>Here's a way to do this without having to use FOPEN. It actually uses the USe command so there is no danger of someone else grabbing the file before you. You can make changes to allow alias, workarea, again, etc.
>
>FUNCTION MyUse
>LPARAMETER lcTableName
>LOCAL lcErrorProc,nErrorNum
>** Store the old ON ERROR code
>lcErrorProc = ON('Error')
>** This is the success value
>nErrorNum = 0
>** Note that we pass the nErrorNum by reference so our
>** on error proc can change it
>ON ERROR DO NotOpen WITH Error(),nErrorNum
>
>** Try opeing the table
>USE &lcTableName
>
>** Reset the error proc
>ON ERROR &lcErrorProc
>RETURN nErrorNum
>
>FUNCTION NotOpen
>LPARAMETER nErrorCode,nErrorNum
>nErrorNum = nErrorCode
>RETURN

Thanks, I really ought to read the documentation more, the example for ON ERROR gives a similar example.

My method was based on conversion from C using a 3rd party library, which had all sorts of nasty habits in the event of an error, which required manual reseting of various things, so it was easier to trap the error in the first place.

I'll update my code accordingly when I get the chance,
Again thanks
Paul
Previous
Reply
Map
View

Click here to load this message in the networking platform