Results 1 to 9 of 9

Thread: Pointers and classes

  1. #1

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Hi there,

    I was wondering if there's a solution to make pointers in VB... It should be with Types because I can't use classes (problems copying them). Well, I did something like this:

    Code:
    Type tObject
      x As Long
      y As Long
    
      Inventory() As tObject
    End Type
    As you can see I can't use it because of circular declaration . If anyone knows how to make this OR to make this with classes, please help me:

    Code:
    'Copy values to Object(0), don't link!
    Object(0) = Object(1)
    Thanks in advance

  2. #2
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    355
    have you ReDimmed the array to the size you want first?
    because if you haven't, it won't work
    otherwise, it should. im doing something similar in my RTS and it works
    buzzwords are the language of fools

  3. #3

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Of course I did

    Well, the problem's that if I have classes and I do something like Object1 = Object2, it does not copy the values but link both objects...

    Anyway, that's not the point. So is there a way to make pointers to types? I need to do this because I want to have objects in the object type, for example an inventory.

    As you can see in my first post, first code lines, I have an array of objects in the type I'm declaring there... And that doesn't work (You can say I need linked lists)

  4. #4
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    355
    what????!!!
    i don't actaully understand what you want to do

    you *can* copy types by simply doing me(1) = me(0)
    as long as they are the same type


    buzzwords are the language of fools

  5. #5

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Yes, I know... but not classes!

    And I also cannot make pointers to types what is actually my problem.

    OK, here's again what I want to do:

    Code:
    Type tObject
      Contained(10) As tObject
    End Type
    Do you see that it doesn't work?
    Well I thought I can make it having a pointer to an object in the type, like a linked list.. so is there a way?
    (Or do you know another solution? Currently I just habe a big array and store the indexes instead of the objects itselves to simulate contained objects)

  6. #6
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    355
    well, no, you can't have a member of a type as the type itself; that really wouldn't work
    but why do you even want to have members of a type as the type itself?

    wouldnt u want:

    Type TObject

    ID as integer
    Weight as integer
    Type as byte

    end type

    etc...



  7. #7

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Well, I thought about linked lists you know... and I need it for the inventory (so an object can containt objects).

    However, I just wanted to know if I can use pointers for types
    Ok then, thx for trying to help... I found a solution ages ago, just wanted to know if there's another way to make it.


  8. #8
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    I've just read that conversation and have no Idea what you're trying to do, but if you want to get a pointer to a Variable use VarPtr(uMyVariabe) this will give you a long pointer to your variable, see my VarPtr post for an example of how to use it

  9. #9

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Thanks Sam, I can need this for another problem

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