Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting parent

Posted on 1998-06-05
3
Medium Priority
?
272 Views
Last Modified: 2010-04-06
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
0
Comment
Question by:pjroy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
rickpet earned 40 total points
ID: 1350743
PJRoy

procedure TForm2.FormCreate(Sender: TObject);
begin
   form2.parent := form1;
end;

procedure TForm2.FormShow(Sender: TObject);
begin
  Left := (Form2.Parent).Left;
  Top := (Form2.Parent).Top;
end;


I don't think this is what you want...Note that Form2 will be inside Form1.  

Form2 should not be autocreated...Project|Options remove Form2 from autocreate.

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2 := TForm2.Create(self);
  Form2.show;
  ShowMessage(Form2.Owner.Name);
end;

procedure TForm2.FormShow(Sender: TObject);
begin
  Form1.hide;
  Left := (Form2.Owner as TWinControl).Left;
  Top := (Form2.Owner as TWinControl).Top;
end;

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  (Form2.Owner as TWinControl).Show;
  Action := caFree;
  Form2 := nil;
end;

0
 

Author Comment

by:pjroy
ID: 1350744
Perfect, it work when the parent is a form. But now I want the parent to be a DBEdit. But it the form2 doesn't position correctly. Why? In a DBEdit control, I want when a user press enter that form2 show up. I want form2 position to be left=left of DBEdit and top=bottom of DBEdit.

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?

0
 
LVL 3

Expert Comment

by:rickpet
ID: 1350745
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
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question