So I have this (almost working) program that uses pointers to dynamic arrays and pointers to records (double-linked list). I declare some lists in a procedure and use them in another by passing pointers to them. Because of some initial errors, I've been passing them as variables i.e. by reference, but on some pages it says that then "the subprogram might inadvertently alter the value of the pointer which will lead to strange results". So what does that mean? Should I not pass them by ref. at all?
I could declare them globally and then not have the need to pass them. But other than that how does passing 'pointers to records (lists)' work? Can I operate with them normally?
I also stumbled upon this problem, which is why I ask here. I declare new lists like this:
procedure CreateList(var first:point; c:byte);
begin
new(first);
first^.previous := NIL;
first^.digit := c;
first^.next := NIL;
end;
Then I used one elsewhere and after that it goes for deletion:
procedure DeleteList(var first:point);
var q:point;
begin
while first <> NIL do
begin
q:= first^.next;
if first^.previous = NIL then writeln('back is right');
if q = NIL then writeln('q is right');
writeln(first^.digit);
dispose(first);
if first = NIL then writeln('first is right');
first:= q;
end;
end;
But it returns Error 216 at disposing. I've put some writelines to ensure it is declared properly. The node apparently isn't nil as it steps into the cycle. Then all three writelns are written which means that previous and next node are both nil and the digit returns 1. When I put writeln after dispose even without condition, it doesn't proceed so it must stop at disposing.. Any tips? I tried deleting the var and passing by value - didn't change anything.
When I tried running this procedure with another in a simple program, it worked.
pointtype? According to the documentation the pointer must by typed. - Ant_222