Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to check for Exclusivity
Message
From
17/10/2001 10:47:23
David Fluker
NGIT - Centers For Disease Control
Decatur, Georgia, United States
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00569279
Message ID:
00569598
Views:
17
Gerard,

Here is a function that will attempt to use a table exclusively, returning .T. if successful and .F. if not. It has the advantage of supporting the entire USE syntax with all it's parameters and being easily inserted into existing code. Just send your USE statement to this function.

If USE myTable IN 43 ALIAS Fred is your USE statement, then =UseExclusive("USE myTable IN 43 ALIAS Fred") will try to open it exclusively.

If only given this five minutes of testing, so you may want to add a few more validations and tweak it the way you want, but so far it seems to work well.

Here's the code.
*:    Function:	UseExclusive
*:			David Fluker, October 2001
*:
*: Description:	Uses a file exclusively, returns .F. if failed
*:
*:      Syntax:	=UseExclusive(cUseStatement)
*:
*:  Parameters:	lcUseStatement - The use statement 
*:******************************************************
lparameter lcUseStatement

LOCAL llRetVal, llAttemptUse, lcCurrentOnError
llRetVal = .T.			&& Return Value
llAttemptUse = .T.		&& Don't attempt USE statement if .F.
lcCurrentOnError = ''	&& Value of current ON("ERROR")


*: Prepare and check use statement passed in as parameter
*: If a check fails, set llAttemptUse to .F.
IF VARTYPE(lcUseStatement) != 'C'
	lcUseStatement = ''
ENDIF

IF NOT (' USE ' $ ' ' + UPPER(lcUseStatement))
	llAttemptUse = .F.
ENDIF

*:
*: Add any additional checks here. 
*:

*: Make it EXCLUSIVE is it's not already
IF NOT ('EXCL' $ UPPER(lcUseStatement))
	lcUseStatement = lcUseStatement + ' EXCLUSIVE '
ENDIF

*: Attempt the USE statement
IF llAttemptUse = .T.
	lcCurrentOnError = ON('ERROR')
	ON ERROR llRetVal = .F.
	&lcUseStatement
	ON ERROR &lcCurrentOnError
ELSE
	llRetVal = .F.
ENDIF

RETURN llRetVal
>Hi.
>I have a form, with a file set up in the data environment.
>On a button of the form, I have code to Zap the file.
>
>How do I:
>(1) Set Exclu on for the file (so that I can zap it)
> (Overall in my APP, Exclu is set off so from the DE, the file will not be open exclusively)
>
>(2) Ensure there is nobody else using the file (including users in non VFP products who could have the file open (e.g. report Writer)
>
>Thanks in advance for any assistance
>
>regards,
>
>Gerard
David.
Previous
Reply
Map
View

Click here to load this message in the networking platform