Why TForm.Handle is a getter instead of a field?

前端 未结 1 409
长情又很酷
长情又很酷 2021-01-25 13:23

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 unexpect

相关标签:
1条回答
  • 2021-01-25 14:01

    The form object can exist even when the underlying OS window doesn't. During those times, the Handle field would be 0, which isn't helpful to code that needs a valid window handle. To ensure you get a valid handle each time you need one, you'd need to call HandleNeeded prior to referring to the Handle field. As a property with a getter, the property can call HandleNeeded for you automatically, making it easier to use the Handle property.

    0 讨论(0)
提交回复
热议问题