Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Closing Views
Message
De
23/02/2018 12:36:33
 
 
À
23/02/2018 01:54:14
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
01658382
Message ID:
01658410
Vues:
45
>>Hi,
>>
>>I am converting my table based app to client server using views. Doing well but got a simple (probably stupid) question. In some of my programs I run I open numerous views, some on the same table using different alias's. It runs fine but should I be closing these views when the prg is done? If so, what code do I use to close them properly? For some reason I cannot find anything in the help file, only tables closed.
>
>For such matters,
>
* before I open the aliases I want closed
>local loCloser
>	loCloser=CREATEOBJECT("closetemp")
>
>* and somewhere I have defined it as
>DEFINE CLASS CloseTemp AS CUSTOM
>	DIMENSION a1[1]
>	nFiles=0
>
>	PROCEDURE INIT
>		THIS.nFiles=AUSED(atemp)
>		IF THIS.nFiles>0
>			ACOPY(atemp, THIS.a1)
>		ELSE
>			THIS.a1=""
>		ENDIF
>
>	PROCEDURE DESTROY
>		LOCAL lcalias
>		FOR i=1 TO AUSED(aNow)
>			lcalias=aNow[i,1]
>			IF ASCAN(THIS.a1, lcalias,-1,-1,1,2+4)=0 AND USED(lcalias)
>				IF CURSORGETPROP("Buffering",lcalias)>1
>					TABLEREVERT(.T.,lcalias)
>				ENDIF
>				USE IN (lcalias)
>			ENDIF
>		ENDFOR
>ENDDEFINE
>
>Declaring the object as local is crucial, because it then gets released when the procedure exits. The release triggers its .destroy() which gets the job done. I wrote this years ago, and I seem to remember it never fails. There may have been some murky cases when the "and used()" would return a wrong result -- the alias was already closed by something -- but that's in cases when I was recovering from an error and this may have collided with error handler.

I like
USE IN SELECT( m.lcAlias )
That doesn't throw an error if m.lcAlias has already been closed, nor does it change your current work area. Helps simplify some of these cleanup tasks.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform