>>>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
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement