Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parent form of a control 1

Status
Not open for further replies.

bobbie100

Programmer
Aug 29, 2003
64
GB
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.
 
Is it always true that the owner of the component is the form?
 
From the Delphi 7 help files:

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top