Code is the worst kind of error because it does not detect itself in 99.99% of cases. You release the object (button control), while VCL assumes that the object exists. In fact, it happens that the object’s memory is freed up but not reused, so the above code will work fine, as if the object had not yet been freed, but still this is an error.
The following simple error illustrates the situation:
type PData = ^TData; TData = record Value: Integer; end; procedure NastyBug; var P: PData; begin New(P); P^.Value:= 2; Dispose(P); // nasty buggy code ShowMessage(IntToStr(P^.Value)); P^.Value:= 22; ShowMessage(IntToStr(P^.Value)); end;
You can test the above code and it should work as expected, because the remaining memory for P is not reused yet, but the code is a clear error.
kludg source share