DCVARGROUP is very helpful for me, but get a problem calling the function twice, the vars are protected. So I save the classes in a static array, and destroy them when the thread is closed.
Now you forget classdestroy() without problems and it is also threadsave. Maybe someone can use it.
regards
Rudolf
Code: Select all
#INCLUDE "class.CH"
FUNCTION DC_VarGroup( cName, aVars )
******************************************************************
static aClass
LOCAL oClass, nAttr, aIvar, xRet, oVars, oVarsInstance, i, ;
aVars2 := {},cPName,aThreads := threadinfo(3),lFound := .f.,x,y,nDel := 0,nSysHndl := -1
default aClass to {}
FOR i := 1 TO Len(aVars)
AAdd(aVars2,aVars[i,1])
NEXT
DEFAULT cName := '1'
cPName := cName
cName := 'VARGROUP_' + str(threadid(),0) + "_" + cName
for x := 1 to len(aThreads)
if aThreads[x,1] = threadid()
nSysHndl := aThreads[x,2]
exit
endif
next x
for x := 1 to len(aClass) // delete classes in closed threads
lFound := .f.
for y := 1 to len(aThreads)
if aClass[x,1] = aThreads[y,1] .and. aClass[x,2] = aThreads[y,2]
lFound := .t. // thread still active
exit
endif
next y
if !lFound
classdestroy(aClass[x,3])
nDel++
endif
next x
asize(aClass,len(aClass)-nDel)
oClass := ClassObject( cName )
IF oClass <> NIL
ClassDestroy(oClass)
//RETURN oClass // Class already exists
ENDIF
nAttr := CLASS_EXPORTED + VAR_INSTANCE
aIVar := AEval( aVars2, {|a| a := {a, nAttr} } ,,, .T.)
oVars := ClassCreate( cName,, aIVar )
oVarsInstance := oVars:new()
FOR i := 1 TO Len(aVars)
oVarsInstance:&(aVars[i,1]) := aVars[i,2]
NEXT
aadd(aClass,{threadid(),nSysHndl,cPName,cName,.f.})
RETURN oVarsInstance