Results 1 to 6 of 6

Thread: Pointers in VB?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    30

    Pointers in VB?

    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?

  2. #2

  3. #3
    Megatron
    Guest
    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.

  4. #4
    jim mcnamara
    Guest
    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.

  5. #5
    Lively Member
    Join Date
    Jul 2000
    Location
    Sydney, Australia
    Posts
    74
    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.

  6. #6
    Lively Member
    Join Date
    Jul 2000
    Location
    Sydney, Australia
    Posts
    74

    Did anyone have an opinion on this??

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width