Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Articles
Recherche: 

Class to close any cursors created after it was instantiated
Dragan Nedeljkovich, January 31, 2007
Generally, datasessions serve this purpose - they create an isolated environment where our code can run and use tables, cursors etc as it pleases, without disturbing other code. Sometimes wee need a little more granularity - to have a routine which may create any number of cursors, open additional t...
Summary
Generally, datasessions serve this purpose - they create an isolated environment where our code can run and use tables, cursors etc as it pleases, without disturbing other code. Sometimes wee need a little more granularity - to have a routine which may create any number of cursors, open additional tables, and close them all when done, without closing any previously open ones. This simple class will do just that.
Description
The idea is quite simple, and so is the code. Use aUsed() in the beginning, to get a snapshot of what is open, and use once more in the end, to see what's open now - and then close anything that wasn't open in the beginning. To do that, just instantiate this class as a local object. It will get that snapshot when instantiated. When it goes out of scope (i.e. your piece of code exits), in its destroy it will do the cleanup. So all you need is to can save the class in CloseTemp.prg, and in your code
local oCloser
oCloser=newobject("CloseTemp", "closetemp.prg")
and the class will do the rest. Keep in mind that it will not touch other datasessions.
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
		For i=1 To Aused(aNow)
			If Ascan(This.a1, aNow[i,1],-1,-1,1,2+4)=0
				Use In aNow[i,1]
			Endif
		Endfor
Enddefine
Dragan Nedeljkovich, Now officially retired
After (and/or along with) playing with Sinclair ZX Spectrum and Atari ST, I left teaching in 1986 and went through a series of machines and operating systems: CP/M (Cobol, Turbo pascal, CB-80 Basic), PDP and VAX (Cobol, Basic Plus 2, scripts), DOS 3.1 through 7.0, Windows 3.1 through XP. Ran several (almost) forgotten networks - RPTI, Lantastic, WFWG, Novell 2.x, 3.x, 4.x, Windows peer-to-peer and eventually NT and just plain IP (Win/Lin mix). After a brief flirt with Clipper in 1988, discovered Fox and went through mFoxplus 2.1 (DOS), Foxplus (Xenix), FP 1.01, 1.02, 2.0, 2.6, VFP 3.0 (briefly), 5.0, 6.0 (SP 1 to 5), 7.0 SP1, 8SP1 and now 9. Maintained one framework, created another (in DOS Fox), helped create yet another one, then used a few more - bought or in-house - frameworks. Always too lazy to type the same sequence more than four times, I'd rather write a builder or some Intellisense. Along the way, promoted a dozen beginners into experienced programmers. IOW, been there, done that, the T-shirts are recycled already, and it's still interesting and fun way to live. Retired in 2019 and finally found time for those pet projects... in Dabo/Python.
More articles from this author
Dragan Nedeljkovich, November 1, 2006
In this article, Dragan Nedeljkovich talks about how to rebuild from Class Browser's export functionality. Ever since Visual FoxPro 3, we have had the object browser. It has this nice feature to export a class or a form as code. Five versions later, it is still there. But, it still produces out code...
Dragan Nedeljkovich, November 27, 1999
As described in the help, padr('abc',20) will give a string with 17 trailing blanks - but try padc(12, 13), or padl(date(), 20) - you will get a string containing the string representation of number 12 or today's date, padded with blanks (or any other string you choose) on the side of your choice. ...
Dragan Nedeljkovich, November 5, 2000
There's a problem of the DataEnvironment which exists in the .scx but not in the .vcx, so when a form is createobject()ed, it has no DE. There are several ways to create one - either in the form designer, or using a session class, or simply opening the tables in code and avoiding the DE altogether (...
Dragan Nedeljkovich, December 2, 2002
This FAQ describes some considerations to take care of when using spaces in directory names when being used with macro substitution.
Dragan Nedeljkovich, September 1, 2006
Following a thread on the Universal Thread, Dragan Nedeljkovich wrote this article on how to make the totals below the grid scroll horizontally together with the grid. Sometimes, we only wish we wrote this much earlier. This article describes a way to calculate those totals, creating fields in some ...