pjroy
asked on
Getting parent
A form1 call form2 like this: form2.show;
How can I know the parent of form2 so I can do something like this in form2: left := parent.left; top := parent.top
How can I know the parent of form2 so I can do something like this in form2: left := parent.left; top := parent.top
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
remember there is a difference between parent and owner.
Parent is used for visual relationships. I.E. CheckBox1's Parent can be GroupBox1. Note when this happens CheckBox1 can only be shown in the window of GroupBox1.
Now CheckBox's owner will most likely be Form1. Owner is in charge of freeing.
So for a recap.
Parent is for window relationships.
Owner is for memory.
To get your DBEdit to align correctly...try this...
Form2.Left := (Sender as TWinControl).Left + (Sender as TWinControl).Parent.Left;
Form2.Top := (Sender as TWinControl).Top + (Sender as TWinControl).Parent.Top;
Form2.show;
Rick
Parent is used for visual relationships. I.E. CheckBox1's Parent can be GroupBox1. Note when this happens CheckBox1 can only be shown in the window of GroupBox1.
Now CheckBox's owner will most likely be Form1. Owner is in charge of freeing.
So for a recap.
Parent is for window relationships.
Owner is for memory.
To get your DBEdit to align correctly...try this...
Form2.Left := (Sender as TWinControl).Left + (Sender as TWinControl).Parent.Left;
Form2.Top := (Sender as TWinControl).Top + (Sender as TWinControl).Parent.Top;
Form2.show;
Rick
ASKER
The result of this code is correct whene the parent is a form, but doesn't work when the parent is DBEdit:
Left := (frmListClient.Owner as TWinControl).Left;
Top := (frmListClient.Owner as TWinControl).Top;
What is the difference?