|
-
October 3rd, 2001, 04:24 PM
#1
Handle to an object as a parameter
Hello all,
I would like to know if there's a way to pass a handle to an object as a parameter of another function in VB.
Below is an example:
public Function someFunction
Dim objTest as AnObject
set objTest = new AnObject.Something
' ... some code
' Now I will call another function that needs to have
' access to this object, so I pass it as a parameter
AnotherFunction objTest
' ... some more code
End Function
private Function anotherFunction(handleToObject as Variant)
' I can now use that variable as a handle to the
' object instantiated above to call its properties
handleToObject.someProperty
Exit Function
End Function
So, can we do something like that or I'll have to instantiate the object all over again in each function?
Please any help is greatly appreciated.
Thank you all in advance.
- Pascal
-
October 4th, 2001, 01:04 AM
#2
Re: Handle to an object as a parameter
The code you gave should work. You just pass along the refference to the object, meaning that you can change properties, call methods, in onther word, the whole stuff.
Tom Cannaerts
[email protected]
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
-
October 4th, 2001, 08:18 AM
#3
Re: Handle to an object as a parameter
Cakkie is right... your code should work fine as is, but an improvement would be to type your handleToObject "as AnObject" if it's always going to be the same kind of object (AnObject) or to "as Object" if the object type will vary. This will help the compile find errors as well as allow for early binding, etc.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|