vba deep copy/clone issue with class object dictionary -


i have dictionary in main sub (key = string; value = class object). class object consists of 2 dictionaries. collect data , check values stored in dictionary values (class object - dictionaries) noticed last values getting stored. mean values in dictionary in main sub pointing same dictionary reference, hence, instances of class objects contain same data. means need make clone of class objects (deep copy?). have done before class objects stored simple values, not dictionaries. need cloning class object contains dictionaries.

main sub

dim dgroup new scripting.dictionary ' main dictionary ' ' loop thru listbox   = 0 userform1.listbox1.listcount - 1     gname = userform1.listbox1.list(i) ' listbox names ' populate temp dictionary     set dic = fnc.get_session_file_elements(mysesfile, gname)  ' ' instantiate new class object     dim newcol new cvm_col     call newcol.init(dic) ' pass dictionary 'constructor'     dgroup.add gname, newcol.clone ' add main sub dictionary '     set dic = nothing ' clear temp dictionary   next 

class object

private delms scripting.dictionary  private ddat scripting.dictionary  ' private sub class_initialize()   set delms = new scripting.dictionary   set ddat = new scripting.dictionary end sub ' public sub init(inp scripting.dictionary)   set delms = inp end sub ' public function clone()   set clone = new cvm_col   set clone.delms = delms ' <-- crashes   set clone.ddat = ddat end function 

normally clone function works when cloning simple data types string or long or double. i've never had dictionary.

to clone dictionary objects in class objects had make following changes:

class object (modified clone function)

public function clone()   set clone = new cvm_col   clone.elms = delms   clone.dat = ddat end function 

(added properties)

public property elms() scripting.dictionary   set elms = delms end property public property let elms(p scripting.dictionary)   set delms = p end property ' public property dat() scripting.dictionary   set dat = ddat end property public property let dat(p scripting.dictionary)   set ddat = p end property 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -