-
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
-
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 :)
-
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)
-
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
-
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)
-
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...
-
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.
-
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
-
Thanks Sam, I can need this for another problem ;)