* 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.
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.