a_dent@fennel.cc.uwa.oz.au (01/14/91)
A few notes on programming with CList class...
1) Don't remove objects within a doForEach loop - the loop is calculated
in advance and removing objects will cause your "each" procedure to be
called with a nil object!
2) If you are having trouble with random crashes traversing lists,
particularly a program which works in the THINK environment but
crashes in an application, then may have bad contents in a list. For some
reason, the THINK environment seems a lot more rugged and able to ignore
nonsense handles. I wrote the following procedure and edited the CList
source, to trap any such occurrences. The Symantec licensing prohibits me
publishing the modified source, but basically you put lines like the following,
inside the Append, Remove, etc.. procedures:
checkHandle(theObject, ' called from Append ');
procedure checkHandle (h: univ Handle; msg: Str255);
var
handleSize: Size;
strHandle: Str255;
begin
handleSize := GetHandleSize(Handle(h));
if handleSize = 0 then begin
NumToString(Ord4(h), strHandle);
debugStr(concat('Bad handle in ', msg, ' = ', strHandle));
end;
end; { checkHandle }
No prizes for guessing what sort of bugs I just tracked down (Hooray!).
Andy Dent A.D. Software phone 09 249 2719
Mac & VAX programmer 94 Bermuda Dve, Ballajura
a_dent@fennel.cc.uwa.oz Western Australia 6066
a_dent@fennel.cc.uwa.oz.AU (international)