E
e_hobsbawm
I have to admit that I still not get how things work with references in
VB.
I have an object that looks like:
---- myObjectClass -----
private dim myColl as collection
private sub class_initialize()
set myColl = new collection
end sub
private sub class_terminate()
set myColl = nothing
end sib
private function add(v as variant)
myColl.add(v)
end function
public function initilize(a as string)
dim b as variant
dim i as integer
b = split(a,";")
for i = lbound(b) to ubound(b)
myColl.add b(i)
next
end function
----------------------------------
Now I want to write an object function that returns a reference to a
new myObjectClass, with just some of the elements in myColl. I wrote it
like this
---- myObjectClass -----
public function return_match(a as string) as myObjectClass
dim newObject as new myObjectClass
for each c in myColl
if a > c then newObject.add(c)
next
return_match = newObject
end function
----------------------------------
I now use it like this:
dim full_list as myObjectClass
dim sub_list as myObjectClass
set full_list as new myObjectClass
full_list.initialize("apples;bananas;citrus;dates;figs")
set sub_list = full_list.return_match("c")
-----------------------------------
I think it works, but I have crashes now and then. Does this have
memory problems, since I allocate a new object in return_match but
never free it? If so, how would I go ahead to return the object as a
reference?
Best Regards
Eric
VB.
I have an object that looks like:
---- myObjectClass -----
private dim myColl as collection
private sub class_initialize()
set myColl = new collection
end sub
private sub class_terminate()
set myColl = nothing
end sib
private function add(v as variant)
myColl.add(v)
end function
public function initilize(a as string)
dim b as variant
dim i as integer
b = split(a,";")
for i = lbound(b) to ubound(b)
myColl.add b(i)
next
end function
----------------------------------
Now I want to write an object function that returns a reference to a
new myObjectClass, with just some of the elements in myColl. I wrote it
like this
---- myObjectClass -----
public function return_match(a as string) as myObjectClass
dim newObject as new myObjectClass
for each c in myColl
if a > c then newObject.add(c)
next
return_match = newObject
end function
----------------------------------
I now use it like this:
dim full_list as myObjectClass
dim sub_list as myObjectClass
set full_list as new myObjectClass
full_list.initialize("apples;bananas;citrus;dates;figs")
set sub_list = full_list.return_match("c")
-----------------------------------
I think it works, but I have crashes now and then. Does this have
memory problems, since I allocate a new object in return_match but
never free it? If so, how would I go ahead to return the object as a
reference?
Best Regards
Eric