I am designing a tree structure...
How can I use pointers? I mean, no mouse pointers but pointers as:
Something -> Anything
:( I can't find a way to do it... Could you please help me?
Printable View
I am designing a tree structure...
How can I use pointers? I mean, no mouse pointers but pointers as:
Something -> Anything
:( I can't find a way to do it... Could you please help me?
Read in here...
http://www.vbforums.com/showthread.p...n+visual+basic
Does this mean I have to use a variable as a pointer?
:( Isn't there another way?
How can this be used?
VB Code:
ObjPtr VarPtr StrPtr
ObjPtr(ClassName) returns the pointer to a COM+ class.
VarPtr(x) returns the pointer to a variable.
StrPtr(strName) returns the pointer to a string.
In order to use these effectively, you will need to use the API MoveMemory in order to move these pointers to a custom UDT for you to use. Then, after you are done, you must move them back.
NOTE that this means that every time you change a linked list's node, you need to call MoveMemory again to move the mew pointer specified in "pNext As Long."
MoveMemory is defined as the following:
VB Code:
Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
If you truly want to set the pCur UDT to POINT to a node in the list like a true linked list would do, you'll have to define your own API function to do so. This isn't so hard, and this may be much easier than moving the memory block back and forth.
Alternatively, you can use classes. By using the Set keyword, you can set one class to EQUAL another.
I am sorry to bug you, MicroBasic... But could you give me an example?
I am really new at this. ;) Let's say this is an opportunity area for me... Right now I am trying to write my own type named "Binary Tree"
Well, to make your custom API, you will have to make a C++ standard DLL that exports a function that will set one pointer equal to another.
To use ovememory, you can do something like:
VB Code:
MoveMemory ByVal Listx.pNext, pCur, Len(MYTYPE) [code to work with pCur] ' Some Code ' Some Other Code [/code to work with pCur] MoveMemory pCur, ByVal Listx.pNext, Len(MYTYPE)
NOE: This is a very crude code. You'll have to refine it on your own.
I can see so but I still don't understand it 100%
Forgive me for insisting but if I don't understand I know I will end up asking again, so I would like to grasp completely the concept.
VB Code:
'Is pCur the Pointer? MoveMemory ByVal Listx.pNext, pCur, Len(MYTYPE) 'Is this like "New(Pointer)"? 'What is Listx.pNext? 'What is MYTYPE? [code to work with pCur] ' Some Code ' Some Other Code 'In here do you mean I am working with the pointer? 'Could this be like x^.name = 'Me'? [/code to work with pCur] MoveMemory pCur, ByVal Listx.pNext, Len(MYTYPE) 'Is this like "Dispose(Pointer)"?
This is just a sample.
VB Code:
MoveMemory ByVal Listx.pNext, pCur, Len(MYTYPE)
This code moves whatever pointer is in Listx.pNext to pCur.
Now you should read data in Cur and do whatever you want with the pointer.
VB Code:
MoveMemory pCur, ByVal Listx.pNext, Len(MYTYPE)
This code moves whatever in in pCur back into the pointer.
The custom API method is much easier, though.
And which might be that custom API?
*Laughs out loudly*
I would hate to reply to myself being so pesky.
Basically make your own DLL in VC++ and export a function that assigns a pointer to another, like:
Now you can use that custom API to point one pointer to another or to assign one pointer to a blank memory space.Code:extern "C" _declspec(dllexport) long CALLBACK repoint(void *a, void *b)
{
if(b != NULL)
delete b;
b = a;
}
extern "C" _declspec(dllexport) long CALLBACK mknew(void *a, long bytes)
{
b = new char[bytes];
}
It is I don't have VC++ since I lack space... :( So what can I do?
Er... Did you forget about me? ::rolleyes::