Really simple one.
What's the easiest way to determine the Form that contains a specified control? I know I could search up through the parents until I find type TForm, but is there an easier way?
You're right about the Parent property - it runs up through the containership to the form. But every component also has an Owner property that goes right to the form. That's the one you want to use.
By default, a form owns all components that are on it. In turn, the form is owned by the application. Thus when the application shuts down and its memory is freed, the memory for all forms (and all their owned components) is also freed. When a form is loaded into memory, it loads all of the components that are on it.
The owner of a component is determined by the parameter passed to the constructor when the component is created. For components created in the form designer, the form is automatically assigned as the Owner.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.