bb.donnay-software.com

Donnay Software Web Forums
It is currently Tue Aug 04, 2020 12:46 am

All times are UTC - 7 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: DCVARGROUP
PostPosted: Mon May 23, 2016 8:56 am 
Offline

Joined: Tue Apr 20, 2010 1:36 am
Posts: 379
Location: SALZBURG/AUSTRIA
Hello,
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:
#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

_________________
Rudolf Reinthaler
digital pen & paper systems
http://www.formcommander.net


Top
 Profile  
 
 Post subject: Re: DCVARGROUP
PostPosted: Mon May 23, 2016 9:31 am 
Offline
Site Admin
User avatar

Joined: Wed Jan 27, 2010 6:58 pm
Posts: 4144
Location: Boise, Idaho USA
Rudolf -

You are correct. That is a much better implementation of DC_VarGroup().

Thank you.

I want to study this concept a bit more before adding it to the next release.

Are you using the DCVARGROUP command in your application, or the DC_VarGroup() function?

Roger

_________________
The eXpress train is coming - and it has more cars.


Top
 Profile  
 
 Post subject: Re: DCVARGROUP
PostPosted: Mon May 23, 2016 11:04 am 
Offline

Joined: Tue Apr 20, 2010 1:36 am
Posts: 379
Location: SALZBURG/AUSTRIA
Hello Roger,
thank you, I user DCVARGROUP and have now added this function in my Lib so that I must not change your sourcecode.
regards
Rudolf

_________________
Rudolf Reinthaler
digital pen & paper systems
http://www.formcommander.net


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group