?
Solved

Getting parent

Posted on 1998-06-05
3
Medium Priority
?
261 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

764 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