On Wed, 5 Nov 1997 14:45:43 +0100 (MET) Peter Gerwinski peter@agnes.dida.physik.uni-essen.de wrote:
According to The African Chief:
[...] Why does the following program behave differently under BP and GPC? [...] StrDispose(p1); if assigned(p1) then p2 := strnew(p1); Writeln(p2); {GPC writes the full string; BP writes "Fred"}
If `StrDispose' does what the name promises, `writeln ( p2 )' should produced *undefined* behaviour.
The problem is that "StrDispose" first of all frees the memory associated with the pChar parameter, and then sets it to Nil - e.g.,
Procedure StrDispose ( Str : PChar ); Begin If ( Str <> Nil ) and ( Str^ <> Chr ( 0 ) ) then begin Free ( Str ); Str := Nil; { doesn't seem to do anything !!!} end; End; {* StrDispose *}
Obviously, the line "Str := Nil" does not actually set it to Nil. I would have to make "Str" a VAR parameter to do this, but I don't want to that (it will become incompatible with BP for one). I have now done a hack to make sure that "Str" points to nothing, by inserting this line; Str^ := #0; before the call to "Free ( Str )". Is there any reason why I shouldn't do this?
Best regards, The Chief Dr Abimbola A. Olowofoyeku (The African Chief, and the Great Elephant) Author of: Chief's Installer Pro v4.01 for Win16 and Win32. Homepage: http://ourworld.compuserve.com/homepages/African_Chief/ E-mail: laa12@keele.ac.uk