I've looked through help files, and I cant find a convention for creating a pointer to any kind of oblect type. What am i missing?
Lets suppose I have an object Foo. What statement will declare a variable that is a pointer to an object of type Foo?
Printable View
I've looked through help files, and I cant find a convention for creating a pointer to any kind of oblect type. What am i missing?
Lets suppose I have an object Foo. What statement will declare a variable that is a pointer to an object of type Foo?
easy answer
vb has no pointers
There are function such as VarPtr, or ObjPtr which will allow you to get the address of variables, but they won't act as pointers, in the sense that C++ dos.
There are three undocumented 'pointer' functions
StrPtr, VarPtr, ObjPtr, plus AddressOf mostly for functions.
But as Mega said, they aren't like C pointers. And they are undocumented for a reason - you can trash your system in a hurry with them.
VB doesn't have pointers in the true sense that C does, but it does do almost the same thing.
Whenever you declare something of a user defined type say
Dim x as MyObjectType
you are not really creating an object, more a pointer to an object of the specified type which is effectively set to be NULL. This is why you cant actually call any of the member functions of x after the above declaration.
The declaration
Dim y as New MyObjectType
declares a new object of MyObjectType and has y pointing to it.
In essence the declarations
Dim x as MyObjectType
Dim y as New MyObjectType
are effectively the same as the following C declarations
MyObjectType* x = NULL;
MyObjectType* y = new MyObjectType;
The main difference in the long run is that if you want to call member functions
in VB:
result = y.func(a,b,c)
in C:
result = y->func(a,b,c);
Hopefully at least some of this makes sense, and if I am spinning crap then I'm sure someone will correct me.
Just wondering if anyone had anything to say about my previous post, as to whether I was talking rubbish or not. Please feel free to let me know if I am deluding myself with my view of VB and pointers.