I've created a class module with name clsABCD and it contains the below code.
Code:
public Data1 as string
public Data2 as string
public Data3 as string
public Data4 as string
public NodeA as clsABCD
public NodeB as clsABCD
public NodeC as clsABCD
public NodeD as clsABCD
In a command button on my form I've placed this code.
Code:
dim test1 as new clsABCD
dim test2 as new clsABCD
dim test3 as new clsABCD
dim test4 as new clsABCD
dim test5 as new clsABCD
set test1.nodea=test2
set test2.nodeb=test3
set test3.nodec=test4
set test4.noded=test5
test5.data1="This"
test5.data2="is"
test5.data3="a"
test5.data4="test."
print test1.nodea.nodeb.nodec.noded.data1
print test1.nodea.nodeb.nodec.noded.data2
print test1.nodea.nodeb.nodec.noded.data3
print test1.nodea.nodeb.nodec.noded.data4
This code works and displays on my form:
This proves that "recursiveness" is something that VB6 can handle (I had my doubts originally when I found there's no way to recursively link variables of a user-defined type).
But writing the complete recursive structure (all nodes and the data they contain) to a file is another problem altogether!
The below code doesn't work.
Code:
Open "c:\temp\test.dat" For Binary As #1
Put #1, 1, test1
Close #1
It gives the error:
Can't Get or Put an object reference or variable or a user-defined type containing an object reference.
I tried this alternative, but it didn't work either.
Code:
Dim propbag As New PropertyBag
propbag.WriteProperty "test", test1
Open "c:\temp\test.dat" For Binary As #1
Put #1, 1, propbag.Contents
Close #1
At the command propbag.WriteProperty it gives the error:
Illegal Parameter. Can't write object because it does not support persistence.
Same thing happened when I tried using a Form instead of a Class Module.
It seems that VB6's class modules (and forms) lack something called "persistence" (whatever that is, I got no clue), and as a result they are UNABLE to be saved to a file. And it's not just because of the recursive nature of what's in the class (or form). ALL forms and class modules in VB6 give this error, under ALL conditions.
And unfortunately it seems class modules and forms are the ONLY only objects that can support recursive structures.
Is there ANY WAY AT ALL around this? Or is saving a recursive structure of any kind from from VB6 a 100% IMPOSSIBLE task?