In short: How do I return an object from a function and make sure that the returned object retains *all* the member variables? I think it's called a 'deep copy' - I may be wrong.
In Long: Read the inline comments...
Function A(ByVal x As String) As MSHTML.HTMLDocument
'creates an object of type MSHTML.HTMLDocument
'and does some stuff with it
'now the *entire* object needs to be returned back
Set A = tempObj
End Function'and does some stuff with it
'now the *entire* object needs to be returned back
Set A = tempObj
Sub B()
Dim obj As MSHTML.HTMLDocument
Set obj=A("xyz")
'Run-time error in the following statement cuz the object which obj refers to
'does not have all the member variables
'objects within the object are discarded, for example obj.body (an object of IHTMLElement) is 'Nothing'
'when in fact it should have lots of things!
Msgbox(obj.getElementById("link1"))
End Sub
Set obj=A("xyz")
'Run-time error in the following statement cuz the object which obj refers to
'does not have all the member variables
'objects within the object are discarded, for example obj.body (an object of IHTMLElement) is 'Nothing'
'when in fact it should have lots of things!
Msgbox(obj.getElementById("link1"))
No comments:
Post a Comment