Solved

How do you shift focus from one mdi child to another?

Posted on 2001-07-11
8
286 Views
Last Modified: 2010-04-06
How do you shift focus from one mdi child to another?

* given:
  2 mdi child forms with an alClient stringgrid and a pop-  up menu each (properties: keypreview=true)
  > mdichild1 and mdichild2

* problem:
  while focus in on mdichild1 ... a "right click event"   of the stringgrid in mdichild2 does not shift the focus from mdichild1 to mdichild2.

* what i want to happen:
  "right click event" of mdichild2 shifts the focus from mdichild1 to mdichild2 so that activemdichild=mdichild2

thanks :)
 
0
Comment
Question by:ttanyag
[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
  • 4
  • 3
8 Comments
 
LVL 1

Expert Comment

by:alx512
ID: 6275768
In OnMouseDown event handler write this code:

procedure TForm2.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Show;
  StringGrid1.SetFocus;
end;
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6276318
Hi ttanyag,

.......
implemenatation
uses
   Unit2;
........

procedure TForm3.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbRight then
    Form2.Show; // Form2 is another MDIChild form.
end;

-----
Igor.
0
 
LVL 1

Accepted Solution

by:
piscean earned 100 total points
ID: 6279218
procedure TForm3.StringGrid1MouseDown(Sender: TObject;
 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if right button was pressed then
    Application.MainForm.Next;
end;
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:alx512
ID: 6279702
You accept a wrong answer, this code work only if you have two Child windows, and what will be if there are three windows?
0
 
LVL 1

Expert Comment

by:piscean
ID: 6279742
I just want to make it clear to you that repeatedly calling the Next method of a MDIParent will switch through all the child forms (no matter how many children are there).  Haven't you passed through this info in the Help file (at least...)  I wonder what happened in your code why the thing you were saying happened!  I can explain these things to you if you want info (huh!)
0
 
LVL 1

Expert Comment

by:alx512
ID: 6279759
Look:

  Form1 - MDI
  Form2 - Child
  Form3 - Child and Focused
  Form4 - Child

You click in Form2 - then Form2 must be Focused,
but your code activate the Form4.
 
0
 
LVL 1

Expert Comment

by:piscean
ID: 6284930
My answer was based on the situation given by "ttanyag".  And that definitely filled his needs so you don't have to be rude saying what I provided was incorrect ('coz it's not!).  The only missing stuff there is the checking whether mdichild2 is in focus or not.  It should be this way rather...

procedure OnMouseDownEvent;
begin
  if right_click and (application.mainform.activemdichild.handle <> handle) then
  application.mainform.next;
end;

Although what you've posted before (Form.Show) was correct, there's a rule here of avoiding duplications so I posted a different one which in turn produces the same result.  The only difference is that I've posted it as an answer and you made yours a comment so it was me that was rated.  We're in the Delphi world man ... one problem has lots of solutions. And that makes us above the others!

About your discussion on having 3 (or more) children.  You're right in saying that the answer I've provided was wrong.  But that can only be WRONG if the problem states that it really will have 3 or more forms!  BUT it was clearly stated that IT HAS ONLY TWO! I should have posted a different answer if the problem said it will have >3 children.  So I guess that cleared your discussion.

And BTW, about this ...
"Look:
Form1 - MDI
Form2 - Child ...".  This will only work on right clicks (not just clicks).  Try left click and everything goes strange ...

0
 
LVL 1

Expert Comment

by:alx512
ID: 6285018
Ok. No problem. I really try to give a common answer.
Good luck!
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

617 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