Nested Arrays And Classes


Recommended Posts

Please let me know what I'm doing wrong here.  I want to have the equivalent of a 2d array, but with named dimensions so instead of having parent[3][2] references I would have parent.marklist[3].marks[2], where marklist and marks were their own classes:

 

class  cChecks
   local marks
   
   function init()
      private i
      for (i = 0, i < 10, i++)
         marks = 0
      endfor
   endfunction
   
endclass
 
class cParent
   local marklist
   
   function init()
      private l
      
      for (l = 0, l < 10, l++)
         marklist[l] = new(cChecks)
         marklist[l].init()
      endfor
   endfunction
   
   
endclass
 
 
global Parent = new(cParent)
Parent.init()
 
private i
private j
 
for (i = 0, i < 10, i++)
   for(j=0, j< 10, j++)
      Parent.MarkList.marks[j] = j
   endfor
endfor
 
?Parent.MarkList[3].Marks  produces 9 not {0,1,2,3,4,5,6,7,8,9} as expected.
 
If I manually assign values, like Parent.Marklist[3].Marks[5] = 32 it will work.  It seems like using class references with two or more [] in a line is having a problem.  This also seems to appear calling a class function with an array reference  topclass[x].myfunction(something[index]).
 
This is all with version 5.90 build 2151.
 
What am I doing wrong?
Link to comment
Share on other sites

As I've mentioned before somewhere here on the forum related to objects, one of the bugs of DAQFactory OOP, and a reason its not considered a release feature is that you can't have more than one () or [] in a symbol.  So, you can do:

 

topclass[x].memberVariable

 

but you can't do:

 

topclass[x].memberArray[y]

 

because there are two []'s in the full symbol.  Same goes if its a function:

 

topclass[x].memberFunction()

 

The workaround is to simply make a reference to topclass[x] first:

 

private tempOb = topClass[x]

tempOb.memberFunction()

Link to comment
Share on other sites

Its not the same expression, otherwise you couldn't do:  sin(x) + cos(y), its only in the same symbol.  Now technically, I suppose, most compilers would split topclass[x].memberFunction() into two symbols, but DAQFactory doesn't, which is, actually, the source of the problem and the eventual fix.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.