What to do with pointer errors ?

Status
Not open for further replies.

Tychom

Ars Tribunus Militum
2,391
Subscriptor
presuming (this is pseudo code, i dont know delphi) that a node in a binary tree was defined
Code:
node:
 some data
 pointer to left child
 pointer to right child

then you could have something defined the same but treated differently which would do what you want (guessing at least, seeing as you havent finished your question)

Code:
node:
 some data
 pointer to sibling
 pointer to child

you'd get a tree like this:
Code:
parent
  |
child-child-child-child
  |           |
child       child-child-child

it's a simple way to do it anyway.
 

skylark

Ars Tribunus Militum
2,388
I don't know what happened. Here is the rest of the question :

Each node must know the list of its children nodes and its father node, and then have an array of pointers pointing to each child, and a separate pointer pointing to the father.

The nodes are complex objects and take a significant amount of memory, so not using pointers would be unwise, or so I thought.
I don't get compilation errors but I keep having a runtime error with this message : "Project X caused an error in KRNL32.DLL", or similar messages with a window popping up and highlighting Assembler instructions as if I could do anything with that.

The firts window appears normally. The error occurs when I try to add the first node.

When I remove all the pointers I get less errors but the application crashes when the 3rd or 4th node is added.

There is not much I can do since these errors aren't syntax related. It seems that pointers don't work in Delphi, but what can you do
without using pointers unless you only program apps of the "Hello world" level.

So I'd like to know how to workaround with pointer errors and any experience with such errors in other languages would be welcome.
And any ideas about how to implement this model without using pointers are useful.


Thanks Tychom, you may have other suggestions now that I have completed the post
:)
 

HL7

Ars Praefectus
3,523
Subscriptor++
Originally posted by skylark:
The nodes are complex objects and take a significant amount of memory, so not using pointers would be unwise, or so I thought.
Actually, in Delphi, everything declared as a class is automatically a pointer. If you're declaring things like mynode : ^TNode, then you're going to have problems.

AFAIK, you should do this:
Code:
var
  mynode: TNode;
begin
  mynode := TNode.Create;
  (do some stuff, pass it to functions, etc)
  mynode.Destroy;
end;
 
Status
Not open for further replies.