I was debugging a complicated bug recently. It was caused by accessing a non-existing Form.Handle
(garbaged pointer). The bug revealed itself in rather unexpected way for me - accessing Forms Handle
caused resizes and repaints.
I would expect accessing Form.Handle
by a garbage pointer would just return some garbage THandle. Expecting that the Handle
is created once on form creation and stays the same till the Form is destroyed.
The question
Why is it so, that TForm.Handle
is not a field that gets initialized on form creation and is accessed via
property Handle: Integer read FHandle;
, but is a getter
property Handle: Integer read GetHandle;
that creates the Handle and even the Window (CreateWnd
) on first access?