Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is table already open under diff alias?
Message
 
 
To
08/02/2010 11:28:52
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01448039
Message ID:
01448079
Views:
54
>>>>>>Hi,
>>>>>>
>>>>>>The only way I know how to determine if a table is already open under some unknown alias is by trying to open the table exclusive and catching the error. Is there another way, maybe simpler?
>>>>>>
>>>>>>TIA.
>>>>>
>>>>>
>>>>>TRY
>>>>>  USE YourTable IN 0 EXCLUSIVE
>>>>>CATCH
>>>>>  MessageBox("The Table is already opened somewhere")
>>>>>ENDTRY
>>>>>
>>>>
>>>>Thank you, Borislav. This works but I forgot to mention that I am trying to find out if the file/table is open by "this" user and not by anyone. That is, if another user of this application has this file open (maybe on another computer), the above code will say that the file is already open. But to me this is not important; I need to find out if this datasession has the file open. Do you see what I mean?
>>>
>>>
>>>lnUsedFiles = AUSED(laUsed)
>>>lbAlreadyUsed = .f.
>>>FOR lnFor = 1 TO m.lnUsedFiles
>>>    IF UPPER(JUSTFNAME(DBF(laUsed[lnFor]))) = "THENAMEOFTHEDBF.DBF"
>>>       lbAlreadyUsed = .t.
>>>       EXIT
>>>    ENDIF
>>>NEXT
>>>IF m.lbAlreadyUsed
>>>   MessageBox("The Table is used  in this datasesion")
>>>ENDIF
>>>
>>>
>>
>>I thought the above would work but it does not. The problem is that I could have the table opened under a different alias loaded in AUSED(). And then I am trying to see if the table is open. For example, if a table MyTable.dbf is open in this datasession under alias MyTable1_Alias and then I am trying to determine if the table MyTable.dbf is open, the above approach would show that NO. But in fact it is open.
>
>
>Dmitry,
>
>Perhaps this function may be of help.
>
>Pass
>- nothing for current workarea
>- an alias name
>- a workarea
>
>
>UPDATE
>
>
>function	GetTableName(wa)
>	wa = evl( m.wa, select(0) )
>	
>	do case
>	case !used(m.wa)
>		return '???'
>		
>	case !empty(cursorgetprop('DataBase', m.wa))
>		return proper(cursorgetprop('SourceName', m.wa))
>	
>	otherwise
>		return Proper(juststem(dbf(m.wa)))
>	
>	endcase
>endfunc
>
Thank you, Gregory.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform